37

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.

3
  • Is this the duplicate declaration error? Commented Jan 19, 2016 at 18:14
  • No, updated question Commented Jan 19, 2016 at 18:18
  • 2
    suppressing certain errors is still a issue :/ Commented Nov 3, 2016 at 11:14

3 Answers 3

42

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.

Sign up to request clarification or add additional context in comments.

Comments

15

UPDATE

This is possible in newer version of TypeScript. See answer from stsloth.

ORIGINAL ANSWER

No, there is not a way to direct the compiler to suppress TS2307. There has been some discussion about it for exactly the reason you describe. For large projects, this becomes a huge barrier to entry.

Details here: Making JavaScript to TypeScript migration easier : Suppress errors

And here: Find a way to suppress the errors generated by importing modules

What you might be able to do is add a step to your build process that filters the error messages. That, of course, depends on how you are doing your builds.

Comments

3

You might find tsc-silent useful. Although, ignoring errors you have to be careful and keep in mind that errors code change, and sometimes there are many different problems reported under umbrella error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.