【发布时间】:2019-03-19 00:00:59
【问题描述】:
我有一个演示项目,我即将编译为 ES5,启用 ES2015 模块,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 - 错误 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 };
如何解决这个问题?
【问题讨论】:
标签: typescript