Reputation: 857
I have problem with creating an object from model in typescript.
export interface ICompliance {
id?: number;
notes?: any;
dueDate?: Moment;
type?: ComplianceType;
createdBy?: string;
updatedBy?: string;
updatedAt?: Moment;
createdAt?: Moment;
file?: IFile;
project?: IProject;
}
export class Compliance implements ICompliance {
constructor(
public id?: number,
public notes?: any,
public dueDate?: Moment,
public type?: ComplianceType,
public createdBy?: string,
public updatedBy?: string,
public updatedAt?: Moment,
public createdAt?: Moment,
public file?: IFile,
public project?: IProject
) {}
}
I am newbie in typescript. How to create an object from model ? any advice ? thanks.
Upvotes: 0
Views: 74
Reputation: 1027
If you want to create an object based on your model. You can just use it as a type instead of implementing it on class.
export class Compliance {
message: ICompliance;
}
Upvotes: 0
Reputation: 437
Since typescript it is just a superset of a javascript you can create object with new
operator.
new Compliance();
https://www.typescriptlang.org/docs/handbook/classes.html
Upvotes: 1