-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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-asserting function call on variable initialized using this
causes false implicit-any in VSCode
#51661
Comments
I've been looking into this for a little bit. I'm very unfamiliar with the Typescript codebase so I'm somewhat flying blind, but from what I can tell, it seems that when resolving the type for |
I digged a little further and found a source of circularity. I'm not sure if it's the only possible one, though. I'll put the full stack trace below in case it's any help but what I saw happening was this:
Through this, I discovered that explicitly specifying the return type as I'm not yet sure why this is only happening in VSCode, but I also noticed that types of things seem to be resolved in a different order when the file is edited vs. loaded fresh. It's possible that the bug is dependent on that order difference. Here's the full call stack on HEAD as I pulled it today (commit Call stack when the circularity was detected
|
I have noticed this too with a slightly different setup (might be a different case). Here's a reproduction
Interestingly enough, the bug does not appear if I assert on
It doesn't happen either if I assign to
|
Bug Report
🔎 Search Terms
asserts, this, vscode, language server, implicit any
🕗 Version & Regression Information
5.0.0-dev.20221128
)This issue seems to be specific to VSCode's TS support - I have not been able to reproduce it in either the Playground nor the Bug Workbench.
tsc
itself accepts this code with no issues.💻 Code
🙁 Actual behavior
Sometimes, usually when freshly loading this code, this works normally. If you edit the function body passed to
callThisFunc
in any way, even stuff like adding superfluous semicolons,maybeN
will become red-underlined and complain about implicit-any
on hover. Further appearances ofmaybeN
in the function are also treated asany
.This error does not happen if you do not call
assertExists
, nor does it happen if you givethis
an explicit type, like so:🙂 Expected behavior
This should not display any errors in VSCode, and the
assertExists
call should correctly narrow the type tonumber
.The text was updated successfully, but these errors were encountered: