test.ts export class Test { whatever(): Promiseany { return undefined; }} 尝试使用旧版本进行编译: $tsc --versionmessage TS6029: Version 1.4.1.0$tsc --target es6 --module commonjs test.ts$cat test.jsvar Test = (function () { fun
export class Test {
whatever(): Promise<any> {
return undefined;
}
}
尝试使用旧版本进行编译:
$tsc --version
message TS6029: Version 1.4.1.0
$tsc --target es6 --module commonjs test.ts
$cat test.js
var Test = (function () {
function Test() {
}
Test.prototype.whatever = function () {
return undefined;
};
return Test;
})();
exports.Test = Test;
这可以.现在有了新版本:
$./node_modules/.bin/tsc --version message TS6029: Version 1.5.0-beta $./node_modules/.bin/tsc --target es6 --module commonjs test.ts error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher.
这是为什么?我正在开发NodeJS应用程序,所以我必须使用commonjs.此外,我需要本机承诺,因此es6目标.
$./node_modules/.bin/tsc --target es5 --module commonjs test.ts test.ts(2,14): error TS2304: Cannot find name 'Promise'.如果要编译为支持ES6的目标,则应使用ES6模块导入,而不是commonjs或AMD.
import * as Promise from 'Promise';
如果提供–target ES6,则在编译时删除–module标志.
