Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mute/ignore TS2307 error from TypeScript tsc

Tags:

typescript

tsc

Is there a way to mute the TS2307 error from the TypeScript tsc compiler?

It makes it really hard to spot real/new errors and warnings as there are many TS2307 errors in our codebase.

Update:

This error occurs when an external module is imported without its type definition .d.ts being present.

I'm aware of tsd but for many libraries we use, no type definitions exist.

like image 632
ᅙᄉᅙ Avatar asked Jan 19 '16 15:01

ᅙᄉᅙ


People also ask

How do I silence a TypeScript error?

Use // @ts-ignore to ignore the type checking errors on the next line in a TypeScript file. If you use a linter, you might have to add a comment to also suppress linting errors when using ts-ignore - // eslint-disable-next-line @typescript-eslint/ban-ts-comment . Copied!

How do I ignore TypeScript for a file?

To ignore all errors in a TypeScript file, we can add the // @ts-nocheck comment. on top of the TypeScript file that we want to ignore all errors for in our code.

How do I tell TypeScript to ignore a line?

Use the // @ts-ignore comment to disable type checking for a line in TypeScript. The comment disables type checking for the next line. If you use a linter, you might need to disable it for the line on which you use the // @ts-ignore comment. Copied!

How do you ignore property does not exist on type?

Use a type assertion to ignore the 'Property does not exist on type' error in TypeScript, e.g. (obj as any). myProperty . Casting the object to any disables type checking and allows us to access any property on the object without getting any errors.


1 Answers

As of TypeScript 2.6 (released on Oct 31, 2017), now there is a way to ignore all errors from a specific line using // @ts-ignore comments before the target line.

The mentioned documentation is succinct enough, but to recap:

// @ts-ignore const s : string = false 

disables error reporting for this line.

However, this should only be used as a last resort when fixing the error or using hacks like (x as any) is much more trouble than losing all type checking for a line.

As for specifying certain errors, the current (mid-2018) state is discussed here, in Design Meeting Notes (2/16/2018) and further comments, which is basically

"no conclusion yet"

and strong opposition to introducing this fine tuning.

like image 156
stsloth Avatar answered Sep 16 '22 12:09

stsloth