使用对象表示法的typescript类继承和实例化
我有一个项目类,它扩展了一个abscract基本类使用对象表示法的typescript类继承和实例化,typescript,inheritance,ecmascript-6,Typescript,Inheritance,Ecmascript 6,我有一个项目类,它扩展了一个abscract基本类 export abstract class Basic { _id?: string; title?: string; titleAbv?: string; description?: string; startDate?: number | Date; endDate?: number | Date; duration?: number | Date; deadline?: n
export abstract class Basic {
_id?: string;
title?: string;
titleAbv?: string;
description?: string;
startDate?: number | Date;
endDate?: number | Date;
duration?: number | Date;
deadline?: number | Date;
constructor(newBasic: BasicInterface) {
this._id = newBasic._id || null;
this.title = newBasic.title || null;
this.titleAbv = newBasic.titleAbv || null;
this.description = newBasic.description || null;
this.startDate = newBasic.startDate || null;
this.endDate = newBasic.endDate || null;
this.duration = newBasic.duration || null;
this.deadline = newBasic.deadline || null;
}
}
export interface BasicInterface {
_id?:string;
title?: string;
titleAbv?: string;
description?: string;
startDate?: number | Date;
endDate?: number | Date;
duration?: number | Date;
deadline?: number | Date;
}
export class Project extends Basic{
color?:number;
clientId?:string;
clientName?:string;
constructor(newProject:ProjectInterface){
super(newProject.basic);
this.color = newProject.color || 0;
this.clientId = newProject.clientId || null;
this.clientName = newProject.clientName || null;
}
}
export interface ProjectInterface{
basic:Basic;
color?:number;
clientId?:string;
clientName?:string;
}
我使用对象符号来实例化,这样输入的顺序就不重要了。但是,我需要用
new Project ({basic:{}})
如果我扩展到项目,它将看起来像
new ObjectExample ( { project:{basic:{}}})
这不是很好,我想知道是否有一种方法可以从类继承并保留对象表示法
谢谢
ProjectInterface扩展了基本接口
?哇……真的很简单……谢谢:D