V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  nebnyp410404  ›  全部回复第 1 页 / 共 1 页
回复总数  3
25 天前
回复了 tmkook 创建的主题 TypeScript typescript 如何返回一个动态对象类型
class schema {
func: Function
}

class a extends schema {
fun1: () => 1
}
class b extends schema{
fun2: () => 2
}

const objs = {
a:new a,
b:new b
}

type Key = keyof typeof objs;

function find<T extends Key>(key: T): typeof objs[T] {
return objs[key];
}

const cc = find('a')
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1297 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 23:48 · PVG 07:48 · LAX 16:48 · JFK 19:48
Developed with CodeLauncher
♥ Do have faith in what you're doing.