首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建react 18和类型记录

创建react 18和类型记录
EN

Stack Overflow用户
提问于 2022-04-09 12:48:18
回答 1查看 2K关注 0票数 3

我试图用TypeScript创建Reactive18应用程序,我试着跟随本指南,但我无法使它工作。我无法将"types": ["react/next", "react-dom/next"]添加到tsconfig文件中。我搞错了:

代码语言:javascript
复制
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

另外,我不能从ReactDom中导入'react-dom/client';,我得到了这个错误:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2022-04-10 17:28:34

上周我花了很长时间才弄明白。在react dom experimental.d.ts文件中:

要在实际项目中加载此处声明的类型,有三种方法。如果您的tsconfig.json已经在"compilerOptions"部分中有一个"types"数组,那么最简单的方法就是向"types"数组中添加"react-dom/experimental"

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

代码语言:javascript
复制
  "types" : [
    "react-dom/experimental"
  ]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71808206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档