Created
December 27, 2021 15:58
-
-
Save lordlycastle/b3a24db5d05aa77547376afdae0f65d5 to your computer and use it in GitHub Desktop.
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 MyClass { | |
public myProp = 13; | |
public static readonly myStaticReadOnlyProp = 99; | |
private myPrivateProp: string | undefined; | |
constructor() { | |
this.myPrivateProp = undefined; | |
} | |
public myPublicFunction() { | |
return 1; | |
} | |
public myPublicFunction2(arg: string): Promise<void> { | |
return Promise.resolve(); | |
} | |
private myPrivateFunction() {return false;} | |
} | |
const keyOf: keyof MyClass = 'myPublicFunction2' | |
type MyFunctions<T> = { | |
[K in keyof T & string]: T[K] extends Function ? `func-${K}` : never | |
}[keyof T & string] | |
const funcName: MyFunctions<MyClass> = 'func-myPublicFunction2'; | |
const instance = new MyClass() | |
function stubFunction<T extends MyClass>(instance: T, method: MyFunctions<T>){ | |
console.log(`class: ${instance} - ${method} : result ${instance[method]()}`); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment