Walt W Walt W - 1 year ago 106
TypeScript Question

Typescript strictNullChecks with limited scope

I'm using the Ionic v2 beta with Typescript, and would love to use

. However, dependencies of my project, such as @angular/core, cause compilation errors when I put
strictNullChecks: true
in my

Is there a way to declare a directory / file / module / class as abiding by strictNullChecks, even when the overall project cannot be compiled with the flag?

It seems that, since
is not the default, it will have extremely limited use (despite being an extremely useful feature) as a result of dependencies that were written without the flag.

Answer Source

If your dependencies are all in .js and .d.ts files (that is, not ts source) then you can use a flag and tell the compiler to skip checking your libs, which will result in no errors from the libs.

There are two new flags for that:


Don’t check a the default library (lib.d.ts) file’s validity


Don’t check a user-defined default library (*.d.ts) file’s validity

And a bit more about it in the What's new in Typescript 2:

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download