Ignore all errors in a typescript file
TypescriptTypescript Problem Overview
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?
Typescript Solutions
Solution 1 - Typescript
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 - Typescript
- You can suppress errors in .ts files using
// @ts-ignore
comments for lines - or use
// @ts-nocheck
after version 3.7 for the whole file.
Solution 3 - Typescript
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 - Typescript
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