【发布时间】:2019-08-13 22:08:21
【问题描述】:
我尝试创建一个通用的 React 和 Typescript 通用库,但在配置项目工作区以同时开发库和应用程序时遇到了太多困难
project
├─ app
│ ├─ package.json
│ ├─ tsconfig.json
│ ├─ webpack.config.js
│ ├─ ... (other config files)
│ ├─ node_modules
│ │ ├─ ...
│ │ ├─ @types
│ │ │ ├─ ...
│ │ │ └─ react
│ │ └─ symlink(lib A)
│ └─ src
│ ├─ *.ts files
│ ├─ *.tsx files
│ └─ index.ts
│
└─ libA
├─ package.json
├─ tsconfig.json
├─ other config files
├─ node_modules
│ ├─ ...
│ └─ @types
│ ├─ ...
│ └─ react
└─ src
├─ *.ts files
├─ *.tsx files
└─ index.ts
如果来自 libA 的源代码在 app 中,则一切编译构建并按预期运行。
在此配置下,libA 已成功构建(tsc)。
在此配置下,app 无法使用以下内容进行编译:
../libA/node_modules/@types/react/index.d.ts:2963:13 - error TS2717: Subsequent property declarations must have the same type. Property 'view' must be of type 'SVGProps<SVGViewElement>', but here has type 'SVGProps<SVGViewElement>'.
一些谷歌搜索建议我应该从 libA 中的 node_modules 中删除反应类型,但这会破坏开发过程的便利性,因为 libA 不会编译。
更多细节:
I develop on Mac.
npm: 6.4.1
node: 8.15.0
typescript: 3.3.3333
webpack: 4
tsconfig libA:
{
"compilerOptions": {
"strict": true,
"noUnusedLocals": true,
"declaration": true,
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"outDir": "dist",
"moduleResolution": "node",
"jsx": "react",
"experimentalDecorators": true,
"baseUrl": "src"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
tsconfig 应用程序:
{
"compilerOptions": {
"strict": true,
"noUnusedLocals": true,
"removeComments": true,
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"outDir": "dist",
"moduleResolution": "node",
"jsx": "react",
"lib": [
"es5",
"es6",
"es7",
"dom"
],
"baseUrl": "src"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
我确实不想使用 skipLibCheck,因为类型是我首先爱上 typescript 的原因...
可以安全地假设我做的事情完全错误..因为我断断续续地做了将近一个星期,无法确定正确的配置..欢迎任何指导...
经过进一步调查,我发现唯一不同的是我是否通过使用 npm 链接到 libA 使用符号链接
【问题讨论】:
-
这个问题已经解决了,我不知道为什么......一旦我知道我会在这里评论它
标签: node.js reactjs typescript webpack