Typescript: What to do when your third party NPM module doesn't have type declarations
However if you want to set your compiler options to strict, you will more than likely run into an issue with third part code coming from NPM. In the form of:
Type error: Could not find a declaration file for module MODULE NAME HERE
Here's a screen grab of the compiler error from my build server...
It's offering a nice line of hope by suggesting I run an npm command to add in the types. Sometime this works, but as not everyone feels the need to adopt TypeScript you'll find there's times when it doesn't.
The only solution to this is to write your own.
Type Definitions are stored in the node_modules folder, but as that isn't something you'll want to be adding to source control you'll need another folder. I call mine @types and have it in the root. Within that folder you then need a folder for each module requiring type definitions. The name of each folder should match the module name.
To make the actual declaration file you'll need to name it index.d.ts and place it in the folder you just created. You can read more about how declaration files should be structured here, however there's an issue with writing a declaration file for a third party module.
1. It's very confusing to work out everything that should go in it
2. It's not your module so it might change
Unless your planning on helping develop the module and create the official type declarations, I suggest an easier option.
Create a file that looks like this:
/// <reference types="node" /> declare module 'module name here';
This is enough to satisfy the compiler. You won't get accurate types for the module, but they would only ever be as good as your interpretation anyway. This will at least unlock the ability for the rest of your application to continue functioning for strict type checking.