“ObjectConstructor"类型上不存在属性“values" [英] Property 'values' does not exist on type 'ObjectConstructor'
问题描述
在下面,我将一个枚举转换为一个数组,看来我的 tsconfig.json 中可能缺少一些东西.
In the following I am converting an enum in to an array, it seems that I may have something missing in my tsconfig.json.
这是脚本:
const menuItems = Object.values(MediaListFilterType).map(value => ({
type: value,
description: () => {
switch (value) {
case value === MediaListFilterType.notPitched:
return 'Exclude already pitched';
break;
case value === MediaListFilterType.notDoublePitched:
return 'Exclude double pitched';
break;
case value === MediaListFilterType.assignedToMe:
return 'Assigned to me';
break;
case value === MediaListFilterType.notAssigned:
return 'Unassigned';
break;
}
}
}));
这给了我这个错误:ObjectConstructor"类型不存在属性values".
和 tsconfig 如下...
and the tsconfig is as follows...
{
"compilerOptions": {
"module": "es6",
"target": "es2015",
"sourceMap": true,
"jsx": "react",
"moduleResolution": "node",
"declaration": false,
"allowSyntheticDefaultImports": true
}
}
我对此有点陌生,所以我不确定我需要在 tsconfig.xml 中更改什么.帮助!
I am a bit new at this so I am not sure what I need to change in the tsconfig. Help!
推荐答案
你有 "target": "es2015",
但 Object.values
不是es2015.它是 es2017 的一部分:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values
You have "target": "es2015",
but Object.values
is not a part of es2015. Its a part of es2017 : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values
使用具有该功能的 "target": "ESNext"
.
这篇关于“ObjectConstructor"类型上不存在属性“values"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!