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
interface IPerson {
name: string
age: number
hobby?: string[]
}
class Person implements IPerson {
name: string
age: number
hobby?: string[]
constructor(name: string, age: number, hobby: string[]) {
this.name = name
this.age = age
this.hobby = hobby
}
}
const output = new Person('john doe', 23, ['swimming', 'traveling', 'badminton'])
console.log(output)