[英]Element implicitly has an 'any' type because expression of type 'string' can't be used to index type style
I don't know how to resolve this error:我不知道如何解决此错误:
"Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ prop_first: string; prop_second: string; }'. No index signature with a parameter of type 'string' was found on type '{ prop_first: string; prop_second: string; }'. : “元素隐式具有'any'类型,因为'string'类型的表达式不能用于索引类型'{ prop_first:string; prop_second:string;}'。没有找到带有'string'类型参数的索引签名在类型 '{ prop_first: string; prop_second: string; }' 上。:
const users = [
{ 'user': 'b', 'age': 12, 'active': true, warnings: [{propertyA: true, propertyB: false}] },
{ 'user': 'a', 'age': 22, 'active': false, warnings: [{propertyB: false}] }
];
const obj = {
propertyA: 'true',
propertyB: 'true',
};
Object.keys(obj).forEach((key, index) => {
obj[key] = !(!!obj[key]);
});
console.log(obj);
const propertyA = true
const properties = {propertyA: true, propertyB: false}
const result = users.filter(user => user.warnings.length && _.some(user.warnings, obj))
console.log(result)
console.log(!!undefined)
any ideas?有任何想法吗?
The error is in this line:错误在这一行:
obj[key] = !(!!obj[key]);
Sometimes the value of key
is a sting.有时
key
的价值是一种刺痛。 You can't use a logical not !
你不能使用逻辑 not
!
on a string.在一个字符串上。
Object.keys(obj)
and obj
should be typed: Object.keys(obj)
和obj
应键入:
const obj: Record<PropertyKey, string | boolean> = {
propertyA: 'true',
propertyB: 'true',
};
(Object.keys(obj) as Array<keyof typeof obj>).forEach((key, index) => {
obj[key] = !(!!obj[key]);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.