Created
December 9, 2019 21:36
-
-
Save mycarrysun/701093224b84d8fe58f7fb74ffd51744 to your computer and use it in GitHub Desktop.
Typescript Decorator function to populate the class properties with the first argument as an object
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
export function InitsWithProps<T extends {new(...args: any[]): {}}>(constructor: T) { | |
return class extends constructor { | |
constructor(...args: any[]) { | |
super(...args); | |
if (args && args.length) { | |
Object.assign(this, args[0]); //args[0] must be an object | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage