'Ignore all errors in a typescript file
I have a large typescript file that I've inherited. The compiler has many complaints with this file, however it works just fine.
I'll come back to it, but is there any way to suppress all warnings/errors in a specific file?
Solution 1:[1]
You can use // @ts-nocheck at the top of the file
Files

Look how its done in the code above.
Check references.
https://devblogs.microsoft.com/typescript/announcing-typescript-3-7/ https://github.com/microsoft/TypeScript/wiki/Type-Checking-JavaScript-
Solution 2:[2]
- You can suppress errors in .ts files using
// @ts-ignorecomments for lines - or use
// @ts-nocheckafter version 3.7 for the whole file.
Solution 3:[3]
This is a little known trick. 2 steps:
- add this triple slash comment to the top of your file
/// <reference no-default-lib="true"/>
- toggle this option:
{
"compilerOptions": {
"skipDefaultLibCheck": true
}
}
Side note, as of 2019.4.11, skipDefaultLibCheck option is marked as DEPRECATED in the doc, but the feature still exists in source code, see this line.
Solution 4:[4]
You could also use loose-ts-check to filter out and ignore some or all TypeScript errors in specific files.
It's used like this after initial setup:
tsc --noEmit | npx loose-ts-check
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | aviv |
| Solution 2 | |
| Solution 3 | hackape |
| Solution 4 | Qtax |
