batgerel.e
batgerel.e

Reputation: 857

how to create an object from model

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

Answers (3)

Soumya Gangamwar
Soumya Gangamwar

Reputation: 1022

private obj = new Compliance ({...});

Upvotes: 2

Muhammad Kamran
Muhammad Kamran

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

Victor
Victor

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

Related Questions