Borislav Hadzhiev
Sat Mar 12 2022·2 min read
Photo by Iwan Shimko
Use the // @ts-nocheck
comment to disable all type checking in a TypeScript
file. If you need to disable all type checking for JavaScript files, set the
checkJs
option to false
in your tsconfig.json
file. When the option is
disabled, errors are not reported in JS files.
// 👇️ ts-nocheck disables type checking for entire file // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck // 👇️ ts-ignore ignores any ts errors on the next line // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore function multiply(a, b) { return a * b; }
The @ts-nocheck comment disables type checking for an entire file.
ban-ts-comment
rule on the previous line.If you need to disable all type checking for JavaScript files, you have to set
the checkJs option to false
in your tsconfig.json
file.
{ "compilerOptions": { "allowJs": true, "checkJs": false, // ... your other options } }
The allowJs option allows you to import JavaScript files in your TypeScript project.
.ts
and .tsx
extensions, but when allowJs
is enabled, you can also import .js
and .jsx
files in your TypeScript files.When the checkJs
option is enabled, errors are reported in all JavaScript
files in your project.
checkJs
to false
disables all error reporting for JavaScript files in your TypeScript project, but you are still able to import and use your Javascript files because the allowJs
option is set to true
.If you only want to disable type checking for a single line, you can use the
// @ts-ignore
comment.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore function multiply(a, b) { return a * b; }
The // @ts-ignore
comment disables all type checking errors on the next line.
If you use a linter, chances are you have to disable it for the line on which
you use @ts-ignore
because most linters have rules against using ts comments.