Categories
TypeScript Answers

How to use @types with TypeScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *