使用扩展语法和带有Typescript的新Set() [英] Using spread syntax and new Set() with typescript

查看:352
本文介绍了使用扩展语法和带有Typescript的新Set()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来获取唯一编号:

I am using following code to get unique numbers:

let uniques = [ ...new Set([1, 2, 3, 1, 1]) ]; // [1, 2, 3]

但是,打字稿报告以下错误:类型'Set'不是数组类型. 我不是忍者打字稿,有人可以告诉我这是怎么回事吗?

However, typescript report following error: Type 'Set' is not an array type. I am not typescript ninja, could someone tell me what is wrong here?

推荐答案

这是缺少的功能. TypeScript目前仅支持数组上的可迭代对象.

This is a missing feature. TypeScript only supports iterables on Arrays at the moment.

这篇关于使用扩展语法和带有Typescript的新Set()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆