likes
comments
collection
share

TypeScript Error 2304: Cannot find name 'div' - CR

作者站长头像
站长
· 阅读数 22

背景

使用 react 官方文档上的命令 npx create-react-app my-app --template typescript 创建个一个 ts 项目,打开后发现 index.tsxApp.tsx 文件有报错。原来是 vscode workspace 中的 ts 版本 和 项目中的 ts 版本不一致所致。

  1. 版本
   "react": "^17.0.2",
   "typescript": "^4.5.5",
  1. 报错如下

TypeScript Error 2304: Cannot find name 'div' - CR

TypeScript Error 2304: Cannot find name 'div' - CR

  1. 解决

vscode -> 设置 -> 工作区,打开 setting.json, 添加:

{
   "typescript.tsdk": "./node_modules/typescript/lib"
}