我正在使用core-ui项目,并且正在尝试在我的组件文件上实现Typescript。我从VSCODE得到一个错误,它不允许我在带有tsx扩展名的文件中使用它。
const TheLayout: React.FunctionComponent = () => {}获取以下错误:
Type annotations can only be used in TypeScript files.ts(8010)我的tsconfig.json文件:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"rootDir": "src",
"outDir": "build",
"noFallthroughCasesInSwitch": true
},
"files.associations": {
"*.tsx": "typescriptreact",
"*.ts": "typescriptreact"
},
"include": [
"src"
]
}

发布于 2021-11-25 02:56:21
有时,在使用VSCode类型检查器扩展时会出现问题。就我个人而言,我安装了Flow Type-Checker,因此出现了线条错误。我把它关掉了,错误就消失了
希望能对你有所帮助!
https://stackoverflow.com/questions/64555077
复制相似问题