Skip to content

Instantly share code, notes, and snippets.

@cenkce
Last active January 7, 2019 08:57
Show Gist options
  • Save cenkce/9288106d62104ca1fb68bfd3871d86df to your computer and use it in GitHub Desktop.
Save cenkce/9288106d62104ca1fb68bfd3871d86df to your computer and use it in GitHub Desktop.
Class as a type. Also use data classes as own parameter type.
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