静音/忽略来自 TypeScript tsc 的 TS2307 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34880522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:13:48  来源:igfitidea点击:

Mute/ignore TS2307 error from TypeScript tsc

typescripttsc

提问by ???

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

有没有办法消除 TypeScripttsc编译器的 TS2307 错误?

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

由于我们的代码库中有许多TS2307 错误,因此很难发现真正的/新的错误和警告。

Update:

更新

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

当外部模块被import编辑而其类型定义.d.ts不存在时,会发生此错误。

I'm aware of tsdbut for manylibraries we use, no type definitions exist.

我知道tsd但对于我们使用的许多库,不存在类型定义。

采纳答案by Seamus

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.

不,没有办法指示编译器抑制 TS2307。正是出于您描述的原因,已经对此进行了一些讨论。对于大型项目,这成为进入的巨大障碍。

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

此处的详细信息:使 JavaScript 到 TypeScript 的迁移更容易:抑制错误

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.

您可以做的是在构建过程中添加一个过滤错误消息的步骤。当然,这取决于您如何进行构建。

回答by stsloth

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

从 TypeScript 2.6(2017 年 10 月 31 日发布)开始,现在有一种方法可以使用// @ts-ignore目标行之前的注释来忽略特定行中的所有错误

The mendtioned documentationis 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.

然而,这应该只在修复错误或使用 hacks 时作为最后的手段使用,比如(x as any)比丢失一行的所有类型检查更麻烦。

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

至于指定某些错误,这里讨论了当前(2018 年中期)的状态,在设计会议笔记(2/16/2018)和进一步的评论中,基本上是

"no conclusion yet"

“没有定论

and strong opposition to introducing this fine tuning.

并且强烈反对引入这种微调。

回答by Pavel Birukov

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

你可能会觉得tsc-silent有用。虽然,忽略错误你必须小心并记住错误代码会改变,有时在伞错误下会报告许多不同的问题。