我有一个演示项目,我将使用ES2015模块编译为ES5,并使用tslib
作为外部TS帮助程序:
package.json
{
"name": "foo",
"scripts": {
"build": "tsc"
},
"dependencies": {
"tslib": "^1.9.3"
},
"devDependencies": {
"typescript": "^3.1.3"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"outDir": "./lib",
"rootDir": "./src",
"importHelpers": true,
"strict": true,
"experimentalDecorators": true
}
}
src/index.ts
function a(target: any) {
return target;
}
@a
export class Foo {}
出现错误:
src/index.ts:5:1 - error TS2354: 此语法需要导入辅助工具,但找不到模块'tslib'。
而lib/index.js
已经正确编译:
import * as tslib_1 from "tslib";
function a(target) {
return target;
}
var Foo = /** @class */ (function () {
function Foo() {
}
Foo = tslib_1.__decorate([
a
], Foo);
return Foo;
}());
export { Foo };
如何解决这个问题?