Sometimes, we want to use @types with TypeScript.
In this article, we’ll look at how to use @types with TypeScript.
How to use @types with TypeScript?
To use @types with TypeScript, we can install the package in the @types
namespace that has the type definitions for the modules we’re using.
For instance, we run
npm install --save @types/lodash
to install the @types/lodash
package in our project to add the TypeScript type definitions for the lodash
module into our project.
Then the TypeScript compiler will get the type info from the type definition files and provide type checking and autocomplete functionality.
Conclusion
To use @types with TypeScript, we can install the package in the @types
namespace that has the type definitions for the modules we’re using.