🔎 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, meanwhile tsc and TS Playground behave as expected.
Steps to Reproduce (NOTE: the error is NOT reproducible in TS Playground):
- Clone https://github.com/cleric-sh/repro/tree/phantom-ts7022-error-in-vscode
- Ensure switched to branch
phantom-ts7022-error-in-vscode
npm i
npm run compile --> observe no compiler errors
- Open
index.ts (in VSCode or another editor utilizing tsserver)
- Error may or may not appear on line 26 on
value (depending on whether analysis is on first pass or not)
- Make a change to the file (e.g. add a space) to trigger tsserver to re-analyse the file.
- Error should definitely be visible now.
- Restart the TS Language Server and error disappears. Make a change, and error re-appears.
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 in tsserver and so I should raise this with the typescript team, so here I am!
⏯ Playground Link
https://tsplay.dev/WkqM2N
💻 Code
function Builder<I>(def: I) {
return def;
}
interface IThing {
doThing: (args: { value: object }) => string
doAnotherThing: () => void
}
Builder<IThing>({
doThing(args: { value: object }) {
/**
* ts7022 is shown on 'value' below.
*
* Only shown when func param 'arg' type is declared. Removing the declaration resolves the error.
* Only shown in vscode. tsc compiles without errors.
* Only shown on second pass, after a change has been made to the file. Initial type check on load shows no errors.
* Only shown when noImplicitAny: true
*
* In a more complex file, declaring this function
* after 'doAnotherThing' prevents the error being
* displayed.
*/
const { value } = this.args
return `${value}`
},
doAnotherThing() { },
})
🙁 Actual behavior
Error is shown on Line 26:
'value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
🙂 Expected behavior
Behaviour in tsserver to match tsc (which does not emit the error).
Not sure exactly what should happen.... I would imagine one of:
this resolves to any, since ThisType isn't used, and thus value should also be any.
this resolve to IThing.
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 since 5.2.2), including 5.4.0-beta.
The error does NOT appear in TS Playground: https://tsplay.dev/WkqM2N
I've noted that the error is:
- Only shown when func param 'arg' type is declared. Removing the declaration resolves the error.
- Only shown in vscode. tsc compiles without errors.
- Only shown on second pass, after a change has been made to the file. Initial type check on load shows no errors.
- Only shown when noImplicitAny: true
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:
- the error doesn't seem to make sense. e.g. why wouldn't
value just be any since this isn't typed?
- the error is inconsistent:
- disappearing if (for example) the returned object from
Builder is assigned to a variable.
- not emitted by TSC or visible in TS Playground
🔎 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.