【发布时间】:2014-04-25 00:02:57
【问题描述】:
我有以下类和接口:
export interface IBody {
body : ListBody;
}
export class Element {
// ...
}
export class Paragraph extends Element implements IBody {
// ...
}
export class Character extends Element {
// ...
}
我有代码,我将在其中获取元素派生对象的数组(不仅仅是段落和字符)。对于那些实现 IBody 的情况,我需要对 body 中的元素采取行动。
查看它是否实现 IBody 的最佳方法是什么?是“if (element.body !== undefined)”吗?
然后我如何访问它? "var bodyElement =
C:/src/jenova/Dev/Merge/AutoTagWeb/client/layout/document/elements/factory.ts(34,27): error TS2012: Cannot convert 'Element' to 'IBody':
Type 'Element' is missing property 'body' from type 'IBody'.
Type 'IBody' is missing property 'type' from type 'Element'.
谢谢 - 戴夫
【问题讨论】:
标签: interface typescript