-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Rule proposal: prevent an explicit : boolean
return type annotation if a predicate return type could be inferred
#9764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1. Though let's be conscious to try to avoid unresolvable conflicts with EFRT if we can. I'm pretty sure the most obvious use case, array callbacks, isn't a hard conflict. I'm not sure off the top of my head whether there are edge cases that would be unresolvable. |
Also, in the weeds, but the rule doc page should say clearly that this is only appropriate for TS >=5.5 |
Were we talking somewhere else about having a |
: boolean
return type annotation if a precidate return type could be inferred: boolean
return type annotation if a predicate return type could be inferred
For visibility: microsoft/TypeScript#60778 has been accepted, and should give us an easy escape hatch strategy for conflicts with explicit-function-return-types |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Description
TS 5.5 introduced Inferred Type Predicates.
TS will try to infer a predicate return type if:
The first point is the kicker -- a lot of people (us included) annotate return types explicitly.
Or they'll annotate their own predicates.
We should introduce a rule that warns if:
This would allow people to lean on TS's inference for much safer code -- explicit type predicates are horridly unsound! TS only enforces that the predicate is assignable to the variable's original type -- not that the predicate is correct.
For example this code is TS valid but it is WILDLY incorrect and will crash at runtime:
Fail Cases
Pass Cases
Additional Info
No response
The text was updated successfully, but these errors were encountered: