typescript - 使用对象属性在打字稿中的其他对象上添加属性?
问题描述
我有一个对象,它具有我想从另一种类型扩展所需的属性,例如:
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'.
解决方案
推荐阅读
- sql - 在选择查询中使用 DB-API 替换列名时,我没有得到预期值而是列名
- css - 所有网络浏览器和移动设备都支持的字体
- angular - 用于 Angular 7 的谷歌云应用程序 yaml
- aws-lambda - 如何从 SQS 触发器中获取单条记录?
- amazon-web-services - 将 pem 私有密钥添加到 AWS KMS
- reactjs - 如何在 React 4 应用程序中使用 bootstrap.min.js
- react-native - 如果他们在一段时间内处于空闲或不活动状态,则对本机注销用户做出反应
- regex - 如何使用正则表达式模式拆分此模式中的句子
- regex - 如何根据字符位置查找具有条件的行?
- office365 - 是否可以将成员添加到对其 SharePoint 网站具有读取权限的 office 365 组