首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Typescript数组上使用set函数

无法在Typescript数组上使用set函数
EN

Stack Overflow用户
提问于 2021-04-15 16:12:48
回答 1查看 119关注 0票数 1

我想使用set函数将一个数组的唯一值转换为一个单独的数组。这是我的代码:

代码语言:javascript
复制
import { readFileSync } from 'fs';
import { Table } from 'apache-arrow';

const arrow = readFileSync('file.arrow');
const table = Table.from(arrow);
const table_array = table.toArray();
var values : string[] = [];

for(let i = 0; i < table_array.length; ++i){
    var str = table_array[i][1]
    var id_val = str.toString().split('.');
    values.push(id_val[6]);
}

var unique_id = [...new Set(values)];

console.log(values)

这是我得到的错误:

代码语言:javascript
复制
error TS2569: Type 'Set<string>' is not an array type or a string type.
var unique_id = [...new Set(values)];

这是控制台输出。我不得不隐藏这些值,但它们是字符串格式的数字:

代码语言:javascript
复制
[
  '####', '####', '####', '####', '####',
  '####', '####', '####', '####', '####',
  '####', '####', '####', '####', '####',
  '####', '####', '####', '####', '####',
  ... 427 more items
]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-15 16:40:33

将此downlevelIteration属性设置为tsconfig.json文件,以允许按照编辑器的建议迭代可迭代对象

代码语言:javascript
复制
{

"compilerOptions": {
       ...

      "downlevelIteration": true
       ...
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67104665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档