What is npm @types and how do they work?

Asked

Viewed 500 times

5

I’m starting a project with NodeJS and TypeScript and the instructor told to install the @types/node, beyond the npm package TypeScript. He quickly quoted that the @types/node creates types in the TypeScript for entities of Node, but I would like a deeper explanation of how this works.

1 answer

2


This package in scope @types is where we can find several useful type definitions, such as the Node type definitions that allow us to use, for example, the require to import modules.

The package @types Node contains type definitions for many libraries, such as Express, Sequelize, Jquery and many others. Basically what it does and:

  • check if the package you are using already has types incorporated and, if you prefer, prefer these;
  • check if the type settings have already been sent with compiler.

This link: Typescript Typings - The Complete Guide To Type Definitions: @types, Compiler Opt-In Types: When To Use Each and Why? has material for explaining Types and I think it’s worth a look. I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.