我在使用开箱即用create-react-app my-app --template typescript项目无法识别任何元素的VSCode 中遇到问题。我不断收到错误无法找到名称 xxx,其中 'xxx' 是我在 JSX 中使用的任何 HTML 元素。
有趣的是,该项目最初将在零编辑的情况下运行。一旦我真正进入App.tsx并更改任何内容或创建一个非常基本的新组件,它就会中断。
这是我尝试按照来自 TypeScript 手册 Github 的本教程制作的一个非常基本的组件。
// src/components/Hello.tsx
import React from 'react';
export const Hello = () => {
return <h1>Hello < /h1>;
};
Run Code Online (Sandbox Code Playgroud)
该项目再次直接从推荐的 TypeScript 模板创建,使用create-react-app my-app --template typescript. 未编辑任何文件。
它带着自己的tsconfig.json准备出发了。
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": …Run Code Online (Sandbox Code Playgroud)