-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Type annotations are frequently ignored in --checkJs #15707
Comments
The compiler honors the type annotation, but since these are all assignments, it is not clear which one is the declaration, it still tries to evaluate the expressions. the assumption is that the right-hand-side of the assignment will have a type we can use, but here The solution here would be to give JSDoc higher precedence. this could mean doing two passes, one to find the JSDoc, and one to compute the expression if none was found. |
The other thing is that Also, shouldn't it be clear that the first one is the declaration? I know TypeScript can handle variables being different types in different parts of the code. I've written code like:
So when we get to |
Based on the discussion in #15747, |
TypeScript Version: 2.3.2
Code
Expected behavior:
This passes.
Actual behavior:
Every once in a while:
It's very inconsistent whether or not this error (and other similar errors) appears. It seems like being part of a larger project makes it much more likely.
Since this bug is much easier to consistently reproduce on larger codebases, I've pushed a commit that reproduces the bug in the context I hit upon it:
https://github.com/Zarel/Pokemon-Showdown/tree/e34c77930a7eaae05a28eb68cbc392c777b8c590
If you checkout this commit and run
tsc
, you'll get three errors which I believe are related:(All three of them disappear when I copy/paste the relevant code into a new file to try to create a simple testcase, and all three are incorrect.)
Here's a screenshot of it failing in Visual Studio Code:
The text was updated successfully, but these errors were encountered: