【问题标题】:Typescript discriminate union where field can be anything but the other discriminant fieldTypescript 判别联合,其中字段可以是除其他判别字段之外的任何内容
【发布时间】:2022-12-02 19:07:32
【问题描述】:

How do I create a discriminated union where I can check either for a statusCode of \'0000\' or not \'0000\', so that the correct object type is used?

type Foo = {
  statusCode: \'0000\',
  something: string
} | {
  statusCode: // any string that is not \'0000\'
  somethingElse: string
  }

    标签: typescript


    【解决方案1】:
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2022-01-14
    相关资源
    最近更新 更多