Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Open
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I havesearched for related issues and found none that match my proposal.
- I have searched thecurrent rule list and found no rules that match my proposal.
- I haveread the FAQ and my problem is not listed.
My proposal is suitable for this project
- My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
- My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
Default parameters anddefault values are only used if the parameter or property isundefined
(either because its value isundefined
or because it is missing). So if we know that a function parameter or property can never beundefined
, then we also know that the default is never actually used. This can be used to detect useless defaults.
Fail Cases
// React props destructuringfunctionBar({ foo=""}:{foo:string}){/* ... */}// destructuring assignmentconst{ foo=""}={foo:"bar"}// default parameter[1,2,3].map((a=42)=>a+1)
Pass Cases
// React props destructuringfunctionBar({ foo}:{foo:string}){/* ... */}functionBar({ foo=""}:{foo?:string}){/* ... */}// destructuring assignmentconst{ foo}={foo:"bar"}// default parameter[1,2,3].map((a)=>a+1)[1,2,3,undefined].map((a=42)=>a+1)
Additional Info
This rule requires strict null checks to be enabled.