Typescript – > ES5问题

我在打字稿中写这个:

const mask = [...Array(10)].map((item) => 0); 

在节点控制台中,它生成一个10个零的数组:

 > [...Array(10)].map((item) => 0); [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] 

一旦在javascript中传输,它会产生:

 var mask = Array(10).slice().map(function (item) { return 0; }); 

但是这不是等同的:

 > Array(10).slice().map(function (item) { return 0; }) [ , , , , , , , , , ] 

我的印象是打字稿应该产生isofunction的代码。 我错了吗? 我应该关注TS正在产生的一切吗?

我用这个configuration使用节点v7,tsc 1.20150623.0:

 { "compilerOptions": { "emitDecoratorMetadata": true, "module": "commonjs", "target": "ES5", "outDir": ".tmp/js", "rootDir": "js" } } 

这是TypeScript中的一个已知和开放的问题 ,应该在TypeScript 2.1中解决。

以下代码:

 [...(new Array(5))] 

翻译成:

 (new Array(5)).slice(); 

但是,ES6的含义是不一样的。 看到下面的输出:

 > [...(new Array(5))] [ undefined, undefined, undefined, undefined, undefined ] > (new Array(5)).slice(); [ , , , , ] 

预期的行为:

 Array.apply(null, Array(5))