仅对定义文件允许隐式任何 [英] Allow implicit any only for definition files

查看:45
本文介绍了仅对定义文件允许隐式任何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 "noImplicitAny": true 选项的 TypeScript 在我的 tsconfig.json 中设置.

I am using TypeScript with the "noImplicitAny": true option set in my tsconfig.json.

我正在使用 typings 来管理类型定义文件,并使用引用包含它们我的应用程序入口点中的路径指令:

I am using typings to manage type definition files and am including them using a reference path directive in the entry point of my app:

/// <reference path="./typings/index.d.ts" />

问题是一些定义文件依赖于隐式any,所以现在我从.d.ts文件中得到了很多编译错误.

The problem is that some of the definition files rely on implicit any, so now I get a lot of compile errors from .d.ts files.

有没有办法禁用/消除这些错误,例如基于路径或文件类型?

Is there a way to disable/silence these errors, for example based on the path or the file type?

推荐答案

随着 TypeScript 2.0 的发布,skipLibCheck 编译器选项,它应该可以解决您的问题:

With the release of TypeScript 2.0, the skipLibCheck compiler option was introduced and it should solve your problem:

TypeScript 2.0 添加了一个新的 --skipLibCheck 编译器选项,该选项会导致跳过声明文件(扩展名为 .d.ts 的文件)的类型检查.当程序包含大型声明文件时,编译器会花费大量时间对已知不包含错误的声明进行类型检查,而跳过声明文件类型检查可能会显着缩短编译时间.

TypeScript 2.0 adds a new --skipLibCheck compiler option that causes type checking of declaration files (files with extension .d.ts) to be skipped. When a program includes large declaration files, the compiler spends a lot of time type checking declarations that are already known to not contain errors, and compile times may be significantly shortened by skipping declaration file type checks.

由于一个文件中的声明会影响其他文件中的类型检查,因此在指定--skipLibCheck时可能无法检测到某些错误.例如,如果非声明文件扩充了声明文件中声明的类型,则可能会导致仅在检查声明文件时报告的错误.然而,在实践中这种情况很少见.

Since declarations in one file can affect type checking in other files, some errors may not be detected when --skipLibCheck is specified. For example, if a non-declaration file augments a type declared in a declaration file, errors may result that are only reported when the declaration file is checked. However, in practice such situations are rare.

它默认为 false 并且可以在你的 tsconfig.json 中启用:

It defaults to false and can be enabled in your tsconfig.json:

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

这篇关于仅对定义文件允许隐式任何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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