【发布时间】:2017-03-27 12:38:02
【问题描述】:
我正在尝试将 TypeScript 与 React Native 一起使用。
这是我的tsconfig.json:
{
"compilerOptions": {
"target": "es2015",
"module": "es2015",
"jsx": "react",
"outDir": "build",
"rootDir": "src",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"preserveConstEnums": true,
"allowJs": true,
"sourceMap": true
},
"filesGlob": [
"typings/index.d.ts",
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"index.android.js",
"index.ios.js",
"build",
"node_modules"
],
"compileOnSave": false
}
我希望将 src 目录中的所有 .ts(x) 文件编译到 build 目录中。
预期:
MyAwesomeReactNativeApp/
├── src/
│ └── index.tsx
└── build/
└── index.js
得到:
MyAwesomeReactNativeApp/
├── src/
│ └── index.tsx
└── build/
├── src/
│ └── index.js
├── index.android.js
├── index.ios.js
└── __tests__/
编译器抱怨:
error TS6059: File '[...]/__tests__/index.android.js' is not under 'rootDir' '[...]/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '[...]/__tests__/index.ios.js' is not under 'rootDir' '[...]/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '[...]/index.android.js' is not under 'rootDir' '[...]/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '[...]/index.ios.js' is not under 'rootDir' '[...]/src'. 'rootDir' is expected to contain all source files.
我在这里做错了什么?
提前谢谢你!
【问题讨论】:
-
[...]s 是否不同(特别是大小写不同)?我在我的 Mach 上看到类似的东西,错误是error TS6059: File '/Users/[...]' is not under 'rootDir' '/users/[...]'. 'rootDir' is expected to contain all source files.。一个是/Users,另一个是/users。