yxcoder

typescript 类型断言问题

  •  
  •   yxcoder · Nov 6, 2023 · 2261 views
    This topic created in 1094 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
    bi531334444
    Nov 6, 2023
    1
    Exclude
    Zhuzhuchenyan
    Zhuzhuchenyan
    Nov 6, 2023
    2
    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   ·   Privacy   ·   Solana   ·   3295 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 04:24 · PVG 12:24 · LAX 20:24 · JFK 23:24
    ♥ Do have faith in what you're doing.