Last active
January 7, 2019 08:57
-
-
Save cenkce/9288106d62104ca1fb68bfd3871d86df to your computer and use it in GitHub Desktop.
Class as a type. Also use data classes as own parameter type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getId = (start): (() => number) => (): number => start++; | |
export class SomeData { | |
static getId = getId(0); | |
public icon: string; | |
public text: string = ""; | |
public color: string; | |
public idPrefix: string = 'data-'; | |
public id: string; | |
constructor(config: SomeData) { | |
Object.assign(this, config); | |
// template logic | |
this.id = config.id || this.idPrefix + SomeData.getId(); | |
} | |
} | |
// usage | |
const data = new SomeData(<SomeData>{icon: "icon.png", color: '#000', text: 'some text'}); | |
const or_clone = new SomeData(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment