Created
September 11, 2018 09:42
-
-
Save zakhenry/ae561ad3d0a00723419d7296c97f28cc to your computer and use it in GitHub Desktop.
Typescript member property reflection
This file contains 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
class Foo { | |
baz: number; | |
} | |
export interface StaticClass<InstanceType = any> { | |
new (...args: any[]): InstanceType; | |
} | |
type Instance<T> = T extends StaticClass<infer U> ? U : never; | |
function describe<T extends StaticClass>(staticClass: T): {[P in keyof Instance<T>]: P} { | |
// can't implement this as classes don't have members at runtime! Need to decorate each property to be able to reflect them. | |
return {} as any; | |
} | |
const description = describe(Foo); | |
const a = description.baz; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment