[英]Do I need to install @types/react to work with React in a TypeScript project?
[英]How to install react beta types for typescript project?
截至目前,react 18 已进入测试版 state。我使用npm install react@beta react-dom@beta
安装测试版,然后使用npm install @types/react @types/react-dom --save-dev
安装类型. 我正在关注这篇文章https://blog.logrocket.com/how-to-use-typescript-with-react-18-alpha/除了它使用@next 标签安装 react 和 react-dom 的部分。 但是当我检查 node_modules/@types/react 时,我找不到本应包含更新定义的next.d.ts
文件。 令人惊讶的是,我无法在网上找到很多关于使用 typescript 和最新的 React Beta 的信息。 感谢您的帮助,谢谢。
来自DefinitelyTyped
存储库中的当前 head 提交:
@types/react/next.d.ts
第 1-24 行:
/**
* These are types for things that are present in the upcoming React 18 release.
*
* Once React 18 is released they can just be moved to the main index file.
*
* To load the types declared here in an actual project, there are three ways. The easiest one,
* if your `tsconfig.json` already has a `"types"` array in the `"compilerOptions"` section,
* is to add `"react/next"` to the `"types"` array.
*
* Alternatively, a specific import syntax can to be used from a typescript file.
* This module does not exist in reality, which is why the {} is important:
*
* ```ts
* import {} from 'react/next'
* ```
*
* It is also possible to include it through a triple-slash reference:
*
* ```ts
* /// <reference types="react/next" />
* ```
*
* Either the import or the reference only needs to appear once, anywhere in the project.
*/
感谢所有回复。 当我安装带有next
标签的react
和react-dom
时,我设法获得了定义。
npm i react@next react-dom@next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.