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

typescript 类型断言问题

  •  
  •   yxcoder · 173 天前 · 575 次点击
    这是一个创建于 173 天前的主题,其中的信息可能已经有所发展或是发生改变。

    type TYPE1 {...}

    type TYPE2 {...}

    type TYPE3 {...}

    type TYPE4 {...}

    type ALL = TYPE1 | TYPE2 | TYPE3 | TYPE4

    问: task 是 TYPE1 | TYPE2 | TYPE3 类型应该怎么表示?(排除 TYPE2 ),这里 ALL 可能有很多种类型,所以不想重新写一遍

    2 条回复    2023-11-06 22:04:19 +08:00
    bi531334444
        1
    bi531334444  
       173 天前
    Exclude
    Zhuzhuchenyan
        2
    Zhuzhuchenyan  
       172 天前
    type A = {a: string};
    type B = {b: string};
    type C = {c: string};
    type D = {d: string};

    type All = A | B | C | D;
    type AllButD = Exclude<All, D>;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2965 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 109ms · UTC 09:12 · PVG 17:12 · LAX 02:12 · JFK 05:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.