Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

typescript class 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)
Comment

PREVIOUS NEXT
Code Example
Typescript :: angular set query params 
Typescript :: Error: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions 
Typescript :: array with multiple types in ts 
Typescript :: ngx-file-drop allow only image or pdf 
Typescript :: typescript comments 
Typescript :: macos fonts download for linux ubuntu 
Typescript :: typescript checkbox event 
Typescript :: reddit requests 429 
Typescript :: How to compare two lists and return the number of times they match at each index in python 
Typescript :: actionscript 
Typescript :: check if schema exists sql server 
Typescript :: howt o make sure its a valid sudoku in python 
Typescript :: google fonts icons size classes 
Typescript :: group elements in list with some attributes 
Typescript :: bullets in latex with header 
Typescript :: subplots matplotlib 
Typescript :: latex two plots in 1 
Typescript :: ts singleton pattern 
Typescript :: remove all comments function in c 
Typescript :: wp search post type results page 
Typescript :: typescript generic record 
Typescript :: typescript array of objects 
Typescript :: rite a script that prints “Hello, World”, followed by a new line to the standard output. 
Typescript :: pass function as argument typescript 
Typescript :: How to add new row to a particular index of a ag grid using angular 7 
Typescript :: avatar image mui not centeered 
Typescript :: sails.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies 
Typescript :: remove showing results woocommerce shortcode 
Typescript :: how to register events bukikt 
Typescript :: cmd move all files to parent directory 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =