Ignore all errors in a typescript file

Typescript

Typescript 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 enter image description here

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:

  1. add this triple slash comment to the top of your file
/// <reference no-default-lib="true"/>
  1. 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWarrick FitzGeraldView Question on Stackoverflow
Solution 1 - Typescript07mm8View Answer on Stackoverflow
Solution 2 - TypescriptAli HabibzadehView Answer on Stackoverflow
Solution 3 - TypescripthackapeView Answer on Stackoverflow
Solution 4 - TypescriptQtaxView Answer on Stackoverflow