Repository navigation
Incorrect ts7022 error emitted by tsserver (not by tsc) #57429
Description
Activity
Andarist commented
on Feb 19, 2024 ContributorMore actionsI was not able to reproduce this using the provided repository.
Just checking that you're noting: The error only appears on subsequent analysis of the file. The first analysis (and compiling with
tsc) will NOT emit the error.Did you try editing the file to re-trigger analysis by
tsserver...?The error is consistently reproducible for me on every machine I have on a fresh clone.

If you don't see the error, then it might related to the environment (which is scary)?
- I'm on an M2 Macbook Pro, on MacOS Sonoma
- VSCode Version: 1.86.2
- typescript 5.4.0-beta
- npm 10.2.4
But I've been able to reproduce this error for months, on many permutations of machine, TS version and node version.
Could you please take another look?
Andarist commented
on Feb 19, 2024 ContributorMore actionsYes, 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?
Andarist commented
on Feb 19, 2024 ContributorMore actionsMacOS 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 😉
RyanCavanaugh commented
on Feb 22, 2024 MemberMore actionsI 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.
- addedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Feb 22, 2024 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
tsserver:D Also interested in how to debug TS in such a way.Ryan Cavanaugh (@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?
Andarist commented
on Feb 23, 2024 ContributorMore actionsSebastian Nemeth (@martaver) feel free to DM me on Twitter ( https://twitter.com/AndaristRake ) or on Discord (my nickname is Andarist)
RyanCavanaugh commented
on Feb 23, 2024 MemberMore actionsI'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
argindoThingis explicitly declared is telling.When no type is explicitly declared for the method's
arg, Typescript defers toIThingfor the method signature's types. In this case,thisis simply alwaysIThing.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
doThing's params should be onthis. Should it be as declared in IThing, or the local, explicit declaration?In this case, Typescript seems to be considering the local, explicit declarations, and since
doStuffreturnsvalueobtained fromthis, the return type ofdoStufftherefore depends on the type ofthis, which in turn depends on the return type ofdoStuff...That must be the circularity.
So since the problem only shows when
noImplicitAnyis enabled, I'm guess Typescript must be looking atvalueand trying to infer a narrower type thanany. In doing so, it needs to inspect the type ofthis.args, and so falls into the circularity.This explains why disabling
noImplicitAnyprevents the error, because it prevents TS from inspectingthis.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 Mateusz Burzyński (@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
valuein the binding pattern after making an edit.Reacted by Ryan CavanaughReacted by Sebastian Nemeth- addedBugA bug in TypeScriptA bug in TypeScriptHelp WantedYou can do thisYou can do thisand removedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Mar 6, 2024 - addedDuplicateAn existing issue was already createdAn existing issue was already createdand removedBugA bug in TypeScriptA bug in TypeScriptHelp WantedYou can do thisYou can do this
on Mar 6, 2024 I suppose I'll close this issue in favour of #57585 and track it there.
- addedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
on Apr 27, 2024 - locked as resolved and limited conversation to collaborators
on Oct 22, 2025
🔎 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:
tsserveremits incorrect TS7022 error, meanwhiletscandTS Playgroundbehave as expected.Steps to Reproduce (NOTE: the error is NOT reproducible in TS Playground):
phantom-ts7022-error-in-vscodenpm inpm 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
tscfor the same source and configuration.I have attempted to raise this issue at:
In
typescript-language-serverI was informed that the error is actually produced intsserverand so I should raise this with thetypescriptteam, so here I am!⏯ Playground Link
https://tsplay.dev/WkqM2N
💻 Code
🙁 Actual behavior
Error is shown on Line 26:
🙂 Expected behavior
Behaviour in
tsserverto matchtsc(which does not emit the error).Not sure exactly what should happen.... I would imagine one of:
thisresolves toany, sinceThisTypeisn't used, and thusvalueshould also beany.thisresolve toIThing.But the
ts7022error 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:
valuejust beanysincethisisn't typed?Builderis assigned to a variable.