labs42io / clean-code-typescript

Clean Code concepts adapted for TypeScript

Home Page:https://labs42io.github.io/clean-code-typescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function arguments (2 or fewer ideally) - Talks about destructing but I don't see destructing used

bluEEil opened this issue · comments

In the example of "Function arguments (2 or fewer ideally)"
There is a talk about destrcuting, which to what I know is:

const object = {a: 1, b: 2};
const {a, b} = object; // This is destrcuting

Now what the code there does is

function createMenu(options: { title: string, body: string, buttonText: string, cancellable: boolean }) {
  // ...
}

createMenu({
  title: 'Foo',
  body: 'Bar',
  buttonText: 'Baz',
  cancellable: true
});

I can't find the destructing here (I don't think declaring option type should be considered as destructing.
In the "Set default objects with Object.assign or destructuring" the last example actually does use destructing unlike in this example.
Maybe the paragraph of "Function arguments" should be changed? Or am I missing something here?

@bluEEil take a look at this example in README:

function createMenu({ title = 'Foo', body = 'Bar', buttonText = 'Baz', cancellable = true }: MenuConfig) {
  // ...
}

The function argument is destructured to access fields and give them default values.