截至目前,react 18已进入beta状态。我使用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标记install-rect和react-dom的部分。但当我检查node_modules/@types/react内部时,我找不到本应包含更新定义的next.d.ts
文件。令人惊讶的是,我在网上找不到很多关于使用最新react测试版打字脚本的信息。感谢您的帮助。
来自DefinitelyTyped
存储库中的当前头提交:
@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