Understanding types

TypeScript needs to span across other JavaScript libraries too if we want to efficiently and globally use TypeScript. TypeScript uses the .d.ts files to provide types of JavaScript libraries that were not written in ES6 or TypeScript. Once the .d.ts file is defined, it becomes very easy to see the return types and provide easy type checking. The TypeScript community is very active and it provides types for most files: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types.

Revisiting our tsconfig.json file, we have specified the option noImplicitAny: true and we need a mandatory *.d.ts file for any of the libraries we use. If we set that option to false, tsc will not give any errors, but that's not a recommended practice at all. Having an index.d.ts file for every library we use is one of the standard practices. We'll look at various topics such as how to install types, what if types are not available, how to generate types, and what the general processes for types are.