4 ms·
In JS we can use JSON/object literal syntax and object destructuring to serve a similar purpose: myFunc({ aBoolFlag : true, anotherBoolFlag
by cphoover 5y ago
In JS we can use JSON/object literal syntax and object destructuring to serve a similar purpose:
myFunc({
aBoolFlag : true,
anotherBoolFlag : false,
aString : "Hello World"
});
const myFunc = ({ aBoolFlag, anotherBoolFlag, aString }) => { /* do something with them... */ };
- kall 5y agoI started doing this because of React but at this point ({}) is my default way of starting a function. The only thing I dislike is that it's not super ergonomic for explicit typescript declarations (but great when using typescript to check .js files).
- stnmtn 5y agoI don't find it too bad to do interface IFunctionParameters { userId: string; name: string; age: number; } const example = ({userId, name, age}: IFunctionParameters) => {...}
- bradstewart 5y agoThe most annoying thing about this to me (and to be clear, I do exactly this all the time) is when you mouseover `example` at a use site, all you see is `IFunctionParameters`, not the definition of `IFunctionParameters`. At least in VS Code.
- stnmtn 5y agoThat's a good point, I've lost count of the times I've hovered my mouse over that IFunctionParameters tooltip expecting a nested tooltip to appear with the actual types