Created
July 14, 2021 16:45
-
-
Save captain-yossarian/8088d3e07b86b502abd5bdc77414d387 to your computer and use it in GitHub Desktop.
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
type ClassType = new (...args: any[]) => any; | |
function merge(derived: ClassType, ...classRefs: ClassType[]) { | |
classRefs.forEach(classRef => { | |
Object.getOwnPropertyNames(classRef.prototype).forEach(name => { | |
const descriptor = Object.getOwnPropertyDescriptor(classRef.prototype, name) | |
// just add condition statement | |
if (name !== 'constructor' && descriptor) { | |
Object.defineProperty( | |
derived.prototype, | |
name, | |
descriptor | |
); | |
} | |
}); | |
}); | |
return derived; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment