【发布时间】:2021-07-14 02:43:40
【问题描述】:
我正在检查 PointDto 对象(point1 和 point2)的 x1、y1 和 z1 字段的相等性
Eg :-
point1 => PointDto:
{
x1: "1.000000",
y1: "1.0",
z1: undefined
pointIndex: 0,
}
point2 => PointDto:
{
x1: 1,
y1: 1,
z1: undefined
pointIndex: 1,
}
const keys: any = {
"x1": "x1",
"y1": "y1",
"z1": "z1"
}
const isEqual = (point1: PointDto, point2: PointDto) => {
return keys.every((key :string) => (isNaN(point1[key]) ? point1[key] : +point1[key]) === point2[key]);
}
但是我收到了以下 typescript 错误,任何人都知道如何编写 (point1[key]) 以使 typescript 编译器满意
元素隐式具有“any”类型,因为“string”类型的表达式不能用于索引类型PointDto。
No index signature with a parameter of type 'string' was found on type PointDto.ts(7053)
【问题讨论】:
-
请分享可重现的例子