Created
December 27, 2021 15:58
-
-
Save lordlycastle/b3a24db5d05aa77547376afdae0f65d5 to your computer and use it in GitHub Desktop.
Revisions
-
lordlycastle created this gist
Dec 27, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ 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]()}`); }