【发布时间】:2018-12-13 18:30:14
【问题描述】:
我有一个看起来像这样的界面
export interface IAppSection {
key: string;
order: number;
header: string;
content: string;
modifiedAt: string;
modifiedByEmployeeId: number;
change: 'added' | 'removed' | 'updated' | 'none';
}
我想做的是在存储此接口相关的对象时将change 默认为none。
我试过change: 'added' | 'removed' | 'updated' | 'none' = 'none',但这不起作用。
我确信我在这里做错了,非常感谢一些关于我如何实现这一点的反馈。
【问题讨论】:
-
我不认为,这在
interface中是可能的。虽然您可以在其constructor中从已实现的类中初始化默认值。
标签: typescript