简体   繁体   中英

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

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM