TypeScript: @ts-nocheck does not disable TS language server for file
The expectation when adding // @ts-nocheck
to a file is that the TS language server stays completely away from that file. Ideally it would do that regardless of file extension or no file extension, but at least for the extensions: .js .ts .jsx .tsx
Tested using the latest Insiders build: 1.71.0-insider (Universal)
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 4.7.3
- OS Version: -
Steps to Reproduce:
Create a new file (CMD+N) and paste in either of these examples:
Example 1:
// @ts-nocheck
<Component someProp={true} />
<OtherComponent />
It gives the red squiggly error: JSX expressions must have one parent element. ts(2657)
If it is auto-detected (or saved) as a JS file.
If it is saved as a TS file it gives the red squiggly errors: '>' expected. ts(1005)
and Unterminated regular expression literal. ts(1161)
and on the last line Expression expected. ts(1109)
.
Example 2:
// @ts-nocheck
<Component someProp={true} />
It gives the red squiggly error: '>' expected. ts(1005)
and Unterminated regular expression literal. ts(1161)
It’s auto-detected as a TS file.
Potentially related issues: https://github.com/microsoft/vscode/issues/74151 and https://github.com/microsoft/TypeScript/issues/26887 and https://github.com/microsoft/TypeScript/issues/47315
But this bug seems to be related to how VS Code handles the TS server, not with TS itself.
Doing CMD+SHIFT+P then >TypeScript: Restart TS server
in VS Code will have all the red squiggly lines disappear and reappear.
Also, if there had been a >TypeScript: Stop TS server
option in VS Code, then // @ts-nocheck
not fully working as expected wouldn’t have been so much of a problem… (I don’t want to disable TS completely in my config, since I need it for other files/projects).
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 21 (7 by maintainers)
Are you in VS Code? Recent versions use AI magic to detect the language of new files based on their content. If you’re pasting code into an untitled file, check the language that’s detected at the bottom right.
It’s for writing and experimentation. I often write some code out in VS Code when trying to test out ideas for myself, or for communicating something to others (code structure etc.). Bits and pieces of code interspersed with commented out lines. I benefit from the regular syntax highlighting, but not from the TS errors.