【问题标题】:How create TS type nested?如何创建嵌套的 TS 类型?
【发布时间】:2021-12-03 14:54:06
【问题描述】:

我的原型

type cityType = {
  name:  string,
  type: number,
  coords: {
    x: number,
    y: number,
  },
  _id: string
}

type routeType = {
  city: cityType[],
  _id: string
}

但我有错误:

此条件将始终返回 'false',因为类型 'string' 和 'cityType' 没有重叠

我要route = [city1, city2, ...]

【问题讨论】:

  • 您也应该显示导致错误的块。

标签: typescript typescript-typings


【解决方案1】:

您的问题是 routeType 是一个对象,而不是一个数组。 试试

const route: routeType = {
  city: [city1, city2, ...],
  _id: 'something'
}

【讨论】:

    猜你喜欢
    • 2020-09-30
    • 2022-12-23
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 2012-03-16
    相关资源
    最近更新 更多