23

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?

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • 1
    Did you tried to put a second tsconfig.json file with `"noImplicitAny": false` to a `typings/` directory? – Terite Oct 07 '16 at 11:54
  • Another possible solution could be to place your `tsconfig.json` file in the directory containing your sources e.g. `src/` instead of placing it in the project root directory. – Terite Oct 07 '16 at 11:58
  • @Terite thanks for the suggestions. I tried adding a second `tsconfig.json` file to the `typings` directory but I was still getting errors. I'd prefer not to restructure my project but I'm not sure if that would work anyway, since the `.d.ts` files would still be included. – Tom Fenech Oct 07 '16 at 15:01

2 Answers2

31

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,
        ...
    },
    ...
}
cartant
  • 57,105
  • 17
  • 163
  • 197
14

if you need to allow implicit any on a single import line you can use //@ts-ignore attribute right before the untyped module import it will ignore the implicit any (as well as all the others possible error of the following line, so it is up to you to make it right) but it is dead easy and solves me a lot of headache in no time

for example for font awesome 5 i've

//@ts-ignore
import fontawesome from '@fortawesome/fontawesome';
//@ts-ignore
import regular from '@fortawesome/fontawesome-free-regular';

fontawesome.library.add(regular);

plus, it works fine with webpack

Mosè Bottacini
  • 4,016
  • 2
  • 24
  • 28