You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we do destructuring params, it usually meant for options or props.
And we sometimes also provide default params to them, especially options: e.g.
functionfoo({ bar =true}={}){}
This mean that if the first argument to foo is undefined, assign it to {} and we then destructure the attribute bar which if undefined, it defaults to true.
First, there is way too much logic going on for just something as simple. Secondly, null will break the assumption pretty badly. e.g. if we pass null as first argument, it will crash. or if we pass null to bar, it will not default to true and take on null value. Although such cases can be now caught in the TypeScript land easily.
This will cover all possible null and undefined cases as mentioned above. much more clear and easily to follow with no special object created implicitly thus actually more performant.
I personally think this rule is prone to error.
When we do destructuring params, it usually meant for
options
orprops
.And we sometimes also provide default params to them, especially options: e.g.
This mean that if the first argument to foo is
undefined
, assign it to{}
and we then destructure the attributebar
which ifundefined
, it defaults totrue
.First, there is way too much logic going on for just something as simple. Secondly,
null
will break the assumption pretty badly. e.g. if we passnull
as first argument, it will crash. or if we pass null tobar
, it will not default totrue
and take onnull
value. Although such cases can be now caught in the TypeScript land easily.I would have prefer the following code
This will cover all possible
null
andundefined
cases as mentioned above. much more clear and easily to follow with no special object created implicitly thus actually more performant.Copy in the rule from here…
https://github.com/lukeapage/eslint-plugin-destructuring
The text was updated successfully, but these errors were encountered: