Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

constructor interface typescript

export interface IBaseEntity {
  id: string

}

export interface IBaseEntityClass {
    new(_id?: string, _data?: any): IBaseEntity
}


class Test implements IBaseEntity {
  id: string
  constructor(_id?: string, _data?: any) {
    this.id = 'MOCK_ID'
  }
}
let baseEntityClass: IBaseEntityClass = Test; // The class test fulfills the contract of IBaseEntityClass

new baseEntityClass("", {}) // constructing through IBaseEntityClass interface
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #constructor #interface #typescript
ADD COMMENT
Topic
Name
8+8 =