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've had this issue with both no npm packages installed. With typescript installed only. And with typescript and a tsconfig.json file.
Note: It is incredibly inconsistent. Sometimes it doesn't happen. Other times changing from the built-in version of typescript to the local version fixes it, sometimes just waiting fixes it. Until you change the code at all (adding/removing whitespace for example) and then it comes back. Installing a different version of typescript removes the error until you change the code as well.
I believe that this is a VSCode centric issue and not a Typescript issue for 2 reasons.
Running npx tsc builds the package just fine without any issues from type errors.
The really weird thing about it is that the typescript language server both knows its fine and reports that error. For example, you can see that the type of makeStringBox is correct:
In addition to that, it appears that running the "Typescript: Reload Project" command fixes it until you change the code.
I was able to reproduce this on the TS compiler itself, but only within the editor. In fact, building the project sometimes fixed the issue. Restarting TS does too.
I've had no success in making a test that reproduces it, though. I did a little debugging, and I feel like the problem is in getSymbolOfNameOrPropertyAccessExpression, for this name, isHeritageClauseElementIdentifier returns true, but then things go wrong beacuse ExpressionWithTypeArguments are no longer things that can only appear in type space (and so the decision about meaning appears to be wrong).
changed the title [-]Typescript Instantiation Expressions are failing[/-][+]Instantiation expressions inconsistently trigger incorrect error messages in editor contexts[/+]on Dec 16, 2022
As Jake Bailey (@jakebailey) has mentioned, I do feel like this is not a parsing bug. If you hover over foo in my example, it correctly displays the following:
Okay, here's what I believe happens - you can notice in in two ways:
You have semantic highlighting enabled (the default in VS Code) or you have inlay hints enabled. These (sometimes) get requested before diagnostics. However, the way semantic classifier queries entities asks for its meaning as a type instead of a value. That triggers an error, and that error gets cached for the subsequent getErr request.
The first thing you do after the language server has loaded or after an edit is you try to get quick info on the usage of bar. That triggers the same bad lookup behavior, which reports an error which gets reported in any following diagnostics request.
Activity
IllusionMH commentedon Aug 3, 2022
What TS version is reported if you hover over TS language details in status bar?
Built-in TS version in VS Code insiders is 4.7.3 which doesn't report error in this case.
ZachHaber commentedon Aug 3, 2022
I've tested it with the built in 4.7.3, local 4.7.4, 4.7.3, 4.7.2, and 4.8-beta.
I also tested it on a fresh insiders install. Literally minutes before I made the issue.
ZachHaber commentedon Aug 3, 2022
To show what I mean by the inconsistency with this bug. Randomly, it won't complain about the error until you modify the code, in which case it'll realize that it forgot to complain.
https://user-images.githubusercontent.com/19843782/182628692-1d72352c-ceba-4c94-ba62-30e196e2be8c.mp4
The really weird thing about it is that the typescript language server both knows its fine and reports that error. For example, you can see that the type of

makeStringBoxis correct:In addition to that, it appears that running the "Typescript: Reload Project" command fixes it until you change the code.
mjbvz commentedon Aug 3, 2022
Here's the TS Server log for this case (using TS 4.8.0-dev.20220801):
Details
Notice how
semanticDiagreturns an error in on initial load, but then doesn't once I type a space at the end of the filexiaoxiangmoe commentedon Sep 16, 2022
Temporary solution:
jakebailey commentedon Sep 19, 2022
I was able to reproduce this on the TS compiler itself, but only within the editor. In fact, building the project sometimes fixed the issue. Restarting TS does too.
jakebailey commentedon Sep 19, 2022
I've had no success in making a test that reproduces it, though. I did a little debugging, and I feel like the problem is in
getSymbolOfNameOrPropertyAccessExpression, for this name,isHeritageClauseElementIdentifierreturns true, but then things go wrong beacuseExpressionWithTypeArguments are no longer things that can only appear in type space (and so the decision aboutmeaningappears to be wrong).BrendanKelowna commentedon Nov 30, 2022
I was having this problem until I ran
npm ciDanielRosenwasser commentedon Dec 16, 2022
The repro we had today was
//at the/*$*/cursor.//Expected: No errors.
Actual:
'bar' refers to a value, but is being used as a type here. Did you mean 'typeof bar'?[-]Typescript Instantiation Expressions are failing[/-][+]Instantiation expressions inconsistently trigger incorrect error messages in editor contexts[/+]DanielRosenwasser commentedon Dec 16, 2022
As Jake Bailey (@jakebailey) has mentioned, I do feel like this is not a parsing bug. If you hover over
fooin my example, it correctly displays the following:DanielRosenwasser commentedon Dec 16, 2022
SEMANTIC HIGHLIGHTING!!!!!
jakebailey commentedon Dec 16, 2022
That's one thing I suspect, but I tested with it disabled and also hit it, so I think there may be more (but maybe I'm wrong).
DanielRosenwasser commentedon Dec 16, 2022
Okay, here's what I believe happens - you can notice in in two ways:
getErrrequest.bar. That triggers the same bad lookup behavior, which reports an error which gets reported in any following diagnostics request.