Home > Blockchain >  What is the purpose of types/react and types/react-dom libraries in react?
What is the purpose of types/react and types/react-dom libraries in react?

Time:01-05

I am working with react 18 in typescript. However, apart from react and react-dom, I also see types/react and types/react-dom libraries in package.json. What is the purpose of these libraries?

CodePudding user response:

The ones with @types prefix are type declaration packages.

  • Some libraries are now including the types in the library for you. Couldn't find the types file for Axios, simply because they have already provided the types, no need for an extra types file.
  • @types/react and @types/react-dom are optional, and are not needed to use React or TypeScript. If you are not using TypeScript in your project, or if you are satisfied with the type inference provided by the TypeScript compiler, you may not need to install these packages.

CodePudding user response:

It is most commonly found in React Typescript. As in Typescript, we have to define types of variables. So when we use React with Typescript, we use types/react to declare the type of the React library and types/react-dom to declare the type of the React-dom library.

  • Related