问题描述
我正在尝试构建一个 typescript 类型,它可以推断当前对象的键并将它们作为 selfMethod
函数的参数。
是否可以引用当前对象的键?我知道 Typescript 还 不支持自引用,但我相信它不会执行无限递归,因此希望找到解决方案。
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');
}
}
给定类似(用某些东西替换Self:
type SelfKeysReference = {[key: string]: (selfMethods: <K extends keyof Self>(key: K) => ReturnType<Self[K]>) => any}
感谢您的帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)