Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow implicit any only for definition files

Tags:

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

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" /> 

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?

like image 533
Tom Fenech Avatar asked Jul 29 '16 10:07

Tom Fenech


People also ask

What are Tsconfig files?

The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.

What is allowJs Tsconfig?

allowJs is the option newly available in 1.8. The TypeScript compiler will run a quick sanity check on . js files for syntax errors but otherwise passes them straight through to the output directory.

What is file D TS?

The "d. ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using something like jQuery or underscore, an existing javascript library. You want to consume those from your typescript code.


1 Answers

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

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.

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.

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

{     "compilerOptions": {         "skipLibCheck": true,         ...     },     ... } 
like image 105
cartant Avatar answered Sep 21 '22 15:09

cartant