Skip to content

Instantly share code, notes, and snippets.

@lordlycastle
Created December 27, 2021 15:58
Show Gist options
  • Save lordlycastle/b3a24db5d05aa77547376afdae0f65d5 to your computer and use it in GitHub Desktop.
Save lordlycastle/b3a24db5d05aa77547376afdae0f65d5 to your computer and use it in GitHub Desktop.
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