Typescript: 当不使用--downlevelIteration时,为迭代的实体提供了更好的错误消息

创建于 2017-05-23  ·  3评论  ·  资料来源: microsoft/TypeScript



TypeScript版本: 2.3.3

代码

String.fromCharCode(...new Uint8Array(0));

预期行为:
我希望没有编译错误。

实际行为:
image
image

我必须编写以下代码:

String.fromCharCode(...Array.from(new Uint8Array(0)));
Bug Error Messages Moderate help wanted

最有用的评论

如果值是可迭代的(即具有Symbol.iterator ),我们应该发出此错误消息

Type '{0}' can only be iterated through when using the '--downlevelIteration' flag.

所有3条评论

使用--downlevelIteration

例如:

tsc --downlevelIteration --lib es5,es2015.iterable a.ts

如果值是可迭代的(即具有Symbol.iterator ),我们应该发出此错误消息

Type '{0}' can only be iterated through when using the '--downlevelIteration' flag.

对于从搜索中来到这里的人,对我来说,使用"target": "es6"解决此问题。 在tsconfig.json没有任何target配置之前。 这是与TypeScript 2.8.1一起使用的。

此页面是否有帮助?
0 / 5 - 0 等级