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
I have a PR to add a quick fix to infer the type as number from such cases in #14786.
Inferring from call sites is something we have decided not to pursue for the TS compiler since its inception, and there are multiple reasons. For example, what if the function is not called? What if the use is in another compilation? What if the call is the error, and not the function declaration? What if the calls in your tests, are not exhaustive?
Moreover, this approach really works for a small snippets of code but does not scale specially with IDE scenarios and you want to know what changing one name mean for the whole compilations. Systems we have seen that take this approach either limit the inference to one file to make it more manageable, or do not care about accuracy.
We believe that type annotations serve better when added to declarations rather than non-local use sites for inference; they help readability and allow tools to correctly check for the user-intended behaviors. Using noImplicitAny to mark locations TypeScript could not figure out types in other locations helps ensure the experience stays consistent and prescriptive.
TypeScript Version: 2.2.1 /
Code
Expected behavior:
a
is typenumber
Actual behavior:
a
is typeany
Try in Flow REPL
Try in TypeScript REPLE
The text was updated successfully, but these errors were encountered: