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
In these cases, they're auto-typed and we use control flow analysis to figure out the type of each of these properties at the end of the constructor's scope.
Similar to what we do for let x; in --noImplicitAny.
Old heuristics are still around, but only when there's no assignment in the constructor.
We also do things like tracking when you have an auto-typed array - same stuff for let x = [] in noImplicitAny.
We could add this to TypeScript files as well.
Now you're saying if an assignment in the constructor is conditional we'll say stuff is potentially undefined - but that might mean that users get more false-positives for potentially uninitialized/undefined errors.
Users can add a JSDoc cast if they need.
Don't need a JSDoc annotation for lateinitialized or whatever yet.
Okay, what about doing this in TypeScript in noImplicitAny?
Definitely not using the old heuristic for JS - just want the constructor CFA checks.
As soon as you allow people to omit property types, people will ask why you can't omit the property itself.
As soon as you misspell an assignment in the constructor, you'd add a new declaration.
Conclusion: 4.0-bound, TypeScript will get auto-typed property declarations.
Inference with Promise-Likes
#37615
Worked on a heuristic when inferring to
T | PromseLike<T>
awaited
, we realized that this sort of inference generalizes when the types are soundly covariant (i.e. covariant on )ReadonlyArray
.awaited
for the recursive unwrapping.Auto-Typed Instance Properties in JS
#37900
this.whatever
within constructors and methods.this.whatever
assignments within a class and consider them assignment declarations.this.foo = this.foo.slice(1);
orthis.foo = this.foo ** 2
;let x;
in--noImplicitAny
.let x = []
innoImplicitAny
.undefined
- but that might mean that users get more false-positives for potentially uninitialized/undefined errors.lateinitialized
or whatever yet.noImplicitAny
?React's
jsx
andjsxs
#34547
The text was updated successfully, but these errors were encountered: