Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will setting "noImplicitAny" in typescript to false disable typechecking?

Tags:

typescript

Typescript adds many features on top of javascript es6 and I am interested in static typing and the private/public/protected keywords.

The biggest limitation that is imposed by the Typescript compiler so far is the inability to use javascript libraries that do not have type definition files(.d.ts).

We were able to compile against a library(cheerio) without type definitions by setting the "noImplicitAny" option to false, but I am concerned that this will allow implicit any in our project's code.

cheerio as well as many other javascript libraries already have type definitions thanks to the DefinitlyTyped project but I can't predict when we will need a javascript library without available type definitions.

When the need will come we will have to set "noImplicitAny" to false. Will this effectively disable some or all of the compile time type-checking?

like image 773
Chedy2149 Avatar asked May 20 '26 04:05

Chedy2149


2 Answers

It's easy to write a type-definition for a library that doesn't have type definitions (example):

// somelib.d.ts
declare module "somelib" {
  const lib: any;
  export = lib;
}

Now you can import the module and use it however you like without type-check errors, without losing type-checking elswhere:

import * as somelib from "somelib";
somelib.doSomething();

You can apparently even write a catch-all wildcard for all libraries (I haven't tried this personally):

declare module "*";
like image 114
Aaron Beall Avatar answered May 21 '26 18:05

Aaron Beall


Instead of using noImplicitAny you might want to use --skipLibCheck since it is more appropriate for your case.

like image 20
Murat Karagöz Avatar answered May 21 '26 19:05

Murat Karagöz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!