上一节中历经千辛万苦终于做成了共享库,编译成一个文件,可以代码提示,可仍有问题让我们困惑就是
而不是
多出的模块声明导致在app中不能使用lib中的类型如
let imageHelper:ImageHelper;
只要把多个ts文件合并成一个ts文件文件就能解决这个问题
这里我写了个nodejs 模块,根据tsconfig中的include (src/index.src.ts) 将多个ts文件合并成一个src/index.ts
参看 https://github.com/inno-tecth/lab/tree/master/ts-004 中的ts-one
"include": [
"src/index.ts"
]
然后在编译 ts就能得到一个js文件和一个d.ts文件
package.json配置
....
"scripts": {
"build": "./node_modules/.bin/tsc",
"one":"node %AppData%/npm/node_modules/ts-one/index.js"
....
npm run one 之后生成src/index.ts文件
npm run build 编译src/index.ts
在app中
npm link libs 关联libs
将index.d.ts放在C:\Users\[]\AppData\Roaming\npm\node_modules\@types\libs 下
npm link @types/libs 关联libs的d.ts 便于提示
再看index.d.ts文件 完美!
网友评论