是否使用对象属性在typescript中的其他对象上添加属性?
我有一个对象,该对象有一个需要从另一个类型扩展的属性,例如:是否使用对象属性在typescript中的其他对象上添加属性?,typescript,Typescript,我有一个对象,该对象有一个需要从另一个类型扩展的属性,例如: interface FabricObjectWithId extends fabric.Object { id: string } 接口INeedPropsOfThisObj没有id,所以在MyObj接口上,我想添加id属性,但我得到了错误。帮忙 这是我的用例: private getObjectOnCanvasById = (id: string) => this.handler.canvas .get
interface FabricObjectWithId extends fabric.Object {
id: string
}
接口INeedPropsOfThisObj没有id,所以在MyObj接口上,我想添加id属性,但我得到了错误。帮忙
这是我的用例:
private getObjectOnCanvasById = (id: string) =>
this.handler.canvas
.getObjects()
.find((obj: FabricObjectWithId) => obj.id === id);
错误消息:
Types of parameters 'obj' and 'value' are incompatible.
Type 'Object' is not assignable to type 'FabricObjectWithId'.
getObjects()
返回什么?它的返回类型似乎不正确。getObjects()
返回什么?它似乎有错误的返回类型。