nebnyp410404 最近的时间轴更新
nebnyp410404

nebnyp410404

V2EX 第 546949 号会员,加入于 2021-06-01 18:16:30 +08:00
今日活跃度排名 22900
nebnyp410404 最近回复了
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   ·   实用小工具   ·   2864 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 12:20 · PVG 20:20 · LAX 05:20 · JFK 08:20
Developed with CodeLauncher
♥ Do have faith in what you're doing.