// @ts-check is a comment that opts one JavaScript file into checking. Put it before the first line of code and the file is checked as if checkJs were on, using the rest of your config (strict, lib, types and so on). It arrived together with checkJs, with TypeScript 2.3.
It is the gentle way to start: no config change, one file at a time, and editors such as VS Code honor it with no jsconfig.json at all. Once most files have it, switch to checkJs and mark the exceptions with // @ts-nocheck instead.
At a glance
| Write | // @ts-check |
|---|---|
| Applies to | The whole file, when it comes before the first line of code |
| With checkJs on | Nothing more: every .js file is checked already |
| With checkJs off | Checks this one file, with the options in your config |
Examples
// @ts-check
const names = ["Ada", "Grace", "Katherine"];
console.log(`${names.lenght} people`);error TS2551: Property 'lenght' does not exist on type 'string[]'. Did you mean 'length'?jsconfig.json for this example
{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"noEmit": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} Where it has to go
Anywhere before the first line of code: after a license header or other comments is fine, after an import or any statement is too late, and the comment is then ignored without a warning. If a file has both // @ts-check and // @ts-nocheck, the later of the two wins.
Without a jsconfig.json
When no config file applies, an editor checks a file with // @ts-check using its own default options, which need not match what tsc would use. A project that cares about the result should still have a jsconfig.json, so the editor and tsc -p jsconfig.json in CI agree.
Gotchas
.tsfiles are always checked; the comment does nothing there.- A comment after the first statement is ignored without a warning, so a misplaced
// @ts-checklooks like a file with no errors.
Questions
Should I use // @ts-check or checkJs?
checkJs for a project you control: every file is checked and new files cannot slip through. // @ts-check while migrating an existing codebase file by file, or for a single script that lives outside any project.
Sources
- JS Projects Utilizing TypeScript · TypeScript handbook
- TypeScript 2.3 release notes · TypeScript handbook
- Type Checking JavaScript Files · TypeScript handbook
- JavaScript in Visual Studio Code: type checking · Visual Studio Code docs
Last reviewed 20 October 2026.