如何禁用/抑制TypeScript库中的错误? [英] How to disable/suppress errors from libraries in TypeScript?

查看:865
本文介绍了如何禁用/抑制TypeScript库中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开了一些编译器开关,以报告代码中的更多问题(例如,严格的null检查).但是我在使用的库中遇到了数十个错误,例如:

I have turned on some compiler switches to report more issues in code (e.g. strict null checks). But I get tens of errors in used libraries, e.g.:

[default] xxx/node_modules/@angular/core/src/util/decorators.d.ts:11:5
    Property 'extends' of type 'Type<any> | undefined' is not assignable to string index type 'Function | any[] | Type<any>'.

在库(例如目录node_modules)中是否有任何方法可以抑制/静音/禁用错误检查?

Is there any way of suppressing/muting/disabling error checking in libraries (e.g. directory node_modules)?

它不能与允许仅对定义文件进行隐式的重复,因为我的问题要广泛得多.我不是在问如何禁用库中的一项特定检查(noImplicitAny),而是要如何禁用库中的 all 检查.但是,该问题的答案也适用于我的问题-"skipLibCheck": true禁用了库中的所有检查.

It can't be a duplicate of Allow implicit any only for definition files because my question is much broader. I am not asking how to disable one specific check (noImplicitAny) in libraries, but how to disable all checks in libraries. However the answer from that question applies to mine as well - "skipLibCheck": true disables all checks in libraries.

推荐答案

此问题不是的重复项定义文件,答案 https://stackoverflow.com/a/39917362/1017211 确实可以解决我的问题.

While this question is not a duplicate of Allow implicit any only for definition files the answer https://stackoverflow.com/a/39917362/1017211 from over there does solve my issue.

编辑tsconfig.json:

{
    "compilerOptions": {
        "skipLibCheck": true,
        ...
    },
    ...
}

这篇关于如何禁用/抑制TypeScript库中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆