简体   繁体   English

React js打字稿在子文件夹中不起作用

[英]React js typescript not working in sub folders

I am using typescript with react js.我正在使用带有反应 js 的打字稿。 Typescript is working when creating tsx files in src folder.在 src 文件夹中创建 tsx 文件时,打字稿正在工作。 But whenever I am using tsx in a sub folder like ex.但是每当我在 ex 之类的子文件夹中使用 tsx 时。 components folder typescript is not working.组件文件夹打字稿不起作用。

tsconfig.json: tsconfig.json:

{"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx" }, "include": ["src"] }

look at newly generated tsconfig using查看新生成的 tsconfig 使用

for web网页版

npx create-react-app my-app --template typescript npx create-react-app my-app --template typescript

for react native用于反应原生

npx react-native init MyApp --template react-native-template-typescript npx react-native init MyApp --template react-native-template-typescript

check the dir on your top imports, when using vscode, there's also an auto suggestion feature when you type component name检查顶部导入的目录,使用 vscode 时,输入组件名称时还有自动建议功能

Hope it helps希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM