V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laters
V2EX  ›  TypeScript

如何从对象的值提取到一个新的类型别名

  •  
  •   laters · 2023-04-12 18:29:32 +08:00 · 880 次点击
    这是一个创建于 378 天前的主题,其中的信息可能已经有所发展或是发生改变。

    How to extract a new type alias from an object's value

    const test = {
    'a': ['music','bbq','shopping'],
    'b': ['move','work']
    };
    

    如何从 test 对象中得到

    type Types = 'music' | 'bbq' | 'shopping' | 'move' | 'work'
    
    1 条回复    2023-05-08 15:14:39 +08:00
    zy0829
        1
    zy0829  
       352 天前
    type Types<T> = T[keyof T]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5444 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:08 · PVG 15:08 · LAX 00:08 · JFK 03:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.