-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Incorrect ts7022 error emitted by tsserver (not by tsc) #57429
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
Comments
I was not able to reproduce this using the provided repository. |
Yes, I tried all of this. I've gone through VS Code update just now and that didn't help me to reproduce this either. Have you gone through "Select TypeScript version..." in the command palette (although I can't repro with neither workspace/vscode version)? |
Yeah... switching between VSCode and Workspace typescript versions doesn't change anything - the error appears either way. This is really interesting... I wonder what could be causing this. Also all extensions disabled... The error is displayed on any version of TS I try so far (anything above 5.2 so far), regardless of VSCode version and my machine. I'm always on MacOS (but also appears predictably on different versions of MacOS). What OS are you on? |
MacOS Monterey - I really doubt that this matters at all though. I could hop on a call someday with you to do some pair debugging if you'd be willing to spend some evening on this 😉 |
I can't get this to repro either, but the fact that it does intermittently repro does sort of make sense. Circularity detection can be path-dependent and the language service can query things in different order depending on user settings (for example, computing semantic highlighting). In theory there's some way to consistently repro this in an automated test (e.g. fourslash) and that's really what we'd need to investigate further. |
I would happy to jump in a help debug this. It would be pretty fun to determine that it was my colour theme in VSCode that triggered a bug in @RyanCavanaugh in your opinion, is the message I am describing erroneous? To my best understanding, I don't see how there can be any circularity in the code I have posted. I am in Helsinki, so my time is UTC+2. Should we take this to another channel? How do you guys normally communicate outside of GH issues? |
@martaver feel free to DM me on Twitter ( https://twitter.com/AndaristRake ) or on Discord (my nickname is Andarist) |
I've never seen a circularity error issued where there wasn't some circularity. Sometimes it's subtle to notice, but it's always there. |
To keep note, I think the fact that error is only present when the type of When no type is explicitly declared for the method's When the type is explicitly declared, then Typescript obtains the method's signature's types from the implementation. In this case, it's not clear what the type of In this case, Typescript seems to be considering the local, explicit declarations, and since That must be the circularity. So since the problem only shows when This explains why disabling However, this still doesn't explain why it only occurs on the second pass. I've tried switching off all extensions and even switching Color Theme now... Going to reach out to @Andarist to dive deeper! |
We dug into this over the call and it turns out that this is the very same issue as the one that I diagnosed recently here. An extra failing test case for this issue can be found here (1 error is expected but today we get 2 instead): /// <reference path="fourslash.ts" />
// @strict: true
//// function Builder<I>(def: I) {
//// return def;
//// }
////
//// interface IThing {
//// doThing: (args: { value: object }) => string
//// doAnotherThing: () => void
//// }
////
//// Builder<IThing>({
//// doThing(args: { value: object }) {
//// const { v/*1*/alue } = this.[|args|]
//// return `${value}`
//// },
//// doAnotherThing() { },
//// })
verify.quickInfoAt("1", "const value: any");
verify.getSemanticDiagnostics([{
message: "Property 'args' does not exist on type 'IThing'.",
code: 2339,
}]); You can actually repro it in the playground but you have to quickly hover over |
I suppose I'll close this issue in favour of #57585 and track it there. |
🔎 Search Terms
incorrect ts7022, wrong ts7022, tsserver only error ts7022
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about 'Type System Behavior'.
Summary:
tsserver
emits incorrect TS7022 error, meanwhiletsc
andTS Playground
behave as expected.Steps to Reproduce (NOTE: the error is NOT reproducible in TS Playground):
phantom-ts7022-error-in-vscode
npm i
npm run compile
--> observe no compiler errorsindex.ts
(in VSCode or another editor utilizingtsserver
)value
(depending on whether analysis is on first pass or not)The code in this repro emits an error that is only visible in VSCode whose intellisense is server by
tsserver
.To compare, the same error is not emitted by
tsc
for the same source and configuration.I have attempted to raise this issue at:
In
typescript-language-server
I was informed that the error is actually produced intsserver
and so I should raise this with thetypescript
team, so here I am!⏯ Playground Link
https://tsplay.dev/WkqM2N
💻 Code
🙁 Actual behavior
Error is shown on Line 26:
🙂 Expected behavior
Behaviour in
tsserver
to matchtsc
(which does not emit the error).Not sure exactly what should happen.... I would imagine one of:
this
resolves toany
, sinceThisType
isn't used, and thusvalue
should also beany
.this
resolve toIThing
.But the
ts7022
error shouldn't be displayed.Additional information about the issue
The error appears with all extensions disabled.
The error appears with all versions of
typescript
(I have checked all versions since5.2.2
), including5.4.0-beta
.The error does NOT appear in TS Playground: https://tsplay.dev/WkqM2N
I've noted that the error is:
Also, in a more complex file, declaring this function after doAnotherThing prevents the error being displayed.
There is generally a lot of strange behaviour in this scenario of using 'this' in a non-class context. The repro is non-sensical, but is the simplest reproduction of the same error I could find.
At least this repro demonstrates:
value
just beany
sincethis
isn't typed?Builder
is assigned to a variable.The text was updated successfully, but these errors were encountered: