Using JavaScript packages that doesn't have types

<2018-05-28 Mon>

I write JavaScript, your write JavaScript, everyone writes JavaScript. I write TypeScript, but you may not write TypeScript.

"Oh!! Who cares?"

"We do.

"If that's the case, use an alternate library, you know, each second, a shit JS library is born OUTTA NOWHERE."

"But I need your types.

JavaScript has too many packages that it even has two Google Maps Library(React). But only one of the library has Type Definitions. It's a pain to write your own definition file. You could dig the source code and contribute a type file or you could simply write a minimal one with functions that you use. Type file is almost all similar to a TS interface.

A basic definition file would be like:

// yourLibrary.d.ts
declare module yourLibrary {
    export interface objectName {
        prop: type

On top of your file, add the following statement:

// someFile.ts
/// <reference path="./path/yourLibrary.d.ts" />

But I've so many packages and writing a definition file for each package is tedious. I just want an ONE VS. ALL way.

Your definition file:

// index.d.ts
declare module "*";

Your statement:

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

The above statement turns off type checking for all the packages, so it's not recommended.