I'm trying to build a typescript type which can infer current object's keys and put them as argument of the selfMethod function.
Is it possible to reference keys of the current object ? I know self-referencing is not supported in Typescript yet but I believe it doesn't perform infinite recursion, as such was hoping for a solution.
const obj = {
act1(selfMethods) {
return 1;
},
act2(selfMethods) {
// Intellisense should say "return type is number" amd only allow "act1" | "act2" as possible argument of selfMethods
return selfMethods('act1');
}
}
Given something like (replacing Self with something:
type SelfKeysReference = {[key: string]: (selfMethods: <K extends keyof Self>(key: K) => ReturnType<Self[K]>) => any}
Thanks for your help!