【问题标题】:Interface field with alternative types具有替代类型的接口字段
【发布时间】:2014-12-22 05:50:45
【问题描述】:

有没有办法在 TypeScript 中定义类似的东西?

interface A {
    x: string | number;
}

我希望接口A 有一个名为x 的成员字段,它可以是stringnumber

【问题讨论】:

    标签: typescript


    【解决方案1】:

    不在当前发布的版本中。您现在需要使用 any。但在下一个版本中,将支持具有该语法的 Union 类型

    更多:http://blogs.msdn.com/b/typescript/archive/2014/11/18/what-s-new-in-the-typescript-type-system.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2018-05-05
      • 2021-01-25
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多