TypeScript Error 2304: Cannot find name 'div' - CRA TS Template
文章目录
背景
使用 react 官方文档上的命令 npx create-react-app my-app --template typescript 创建个一个 ts 项目,打开后发现 index.tsx 和 App.tsx 文件有报错。原来是 vscode workspace 中的 ts 版本 和 项目中的 ts 版本不一致所致。
- 版本
"react": "^17.0.2",
"typescript": "^4.5.5",- 报错如下


- 解决
vscode -> 设置 -> 工作区,打开 setting.json, 添加:
{
"typescript.tsdk": "./node_modules/typescript/lib"
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论