gpt4 book ai didi

reactjs - 使用 typescript 创建 React 应用程序 React 18

转载 作者:行者123 更新时间:2023-12-05 05:43:31 25 4
gpt4 key购买 nike

我正在尝试使用 TypeScript 创建 React 18 应用程序,我尝试遵循 this guide但我无法让它发挥作用。我无法将 "types": ["react/next", "react-dom/next"] 添加到 tsconfig 文件。我收到错误:

Cannot find type definition file for 'react-dom/next'.
The file is in the program because:
Entry point of type library 'react-dom/next' specified in compilerOptionsts
Cannot find type definition file for 'react-dom/next'.
The file is in the program because:
Entry point of type library 'react-dom/next' specified in compilerOptionsts

此外,我无法从 'react-dom/client' 导入 ReactDom; 我收到此错误:

Could not find a declaration file for module 'react-dom/client'. 'C:/Users/bansc/Desktop/youtube-channel/api-calls/my-app/node_modules/react-dom/client.js' implicitly has an 'any' type.
If the 'react-dom' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-dom'ts(7016)

最佳答案

上周我花了太长时间才弄清楚这个问题。在 react-dom experimental.d.ts 文件中:

To load the types declared here in an actual project, there are threeways. The easiest one, if your tsconfig.json already has a "types"array in the "compilerOptions" section, is to add"react-dom/experimental" to the "types" array.

因此,将其添加到您的 tsconfig.json 中:

  "types" : [
"react-dom/experimental"
]

关于reactjs - 使用 typescript 创建 React 应用程序 React 18,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71808206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com