V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yxcoder

typescript 类型断言问题

  •  
  •   yxcoder · Nov 6, 2023 · 1820 views
    This topic created in 915 days ago, the information mentioned may be changed or developed.

    type TYPE1 {...}

    type TYPE2 {...}

    type TYPE3 {...}

    type TYPE4 {...}

    type ALL = TYPE1 | TYPE2 | TYPE3 | TYPE4

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

    2 replies    2023-11-06 22:04:19 +08:00
    bi531334444
        1
    bi531334444  
       Nov 6, 2023
    Exclude
    Zhuzhuchenyan
        2
    Zhuzhuchenyan  
       Nov 6, 2023
    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>;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2516 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 00:29 · PVG 08:29 · LAX 17:29 · JFK 20:29
    ♥ Do have faith in what you're doing.