Enhancement: [ban-types] Suggest NonNullable<unknown>
as an alternative for {}
and Object
#6486
Closed
4 tasks done
Labels
accepting prs
Go ahead, send a pull request that resolves this issue
enhancement: plugin rule option
New rule option for an existing eslint-plugin rule
good first issue
Good for newcomers
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/ban-types/
Description
The rule forbids the use of the type
{}
(and its synonymObject
), which means "any non-nullish value", and gives some helpful suggestions on what to use instead, depending on what the developer actually might have meant.However, there seems to be no suggestion (outside disabling the rule) for what to use when the intended meaning really is "any non-nullish value". The suggested alternative for "any object", namely
object
, doesn't include primitive types such asnumber
, so it's not an equivalent replacement in this case.Rather than bypassing or disabling the rule, and leaving the easily misunderstood
{}
in place, I think it would be useful to suggest an explicit alternative for this case as well; something along the lines of(placed after all the other suggestions).
TypeScript includes the
NonNullable
utility type since 2.8, so I don't think there shouldn't be any compatibility issues.PS: I wasn't sure if this issue should go under Documentation or Enhancement; since it changes the output of the rule I opted for the latter. My apologies if I got it wrong :)
Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: