【问题标题】:TS2740 is missing the following properties from type, Typescript, NestJSTS2740 缺少 type、Typescript、NestJS 的以下属性
【发布时间】:2023-03-07 19:29:06
【问题描述】:

我有一个接口,用于详细输入值:

input DocumentDetailInput {
  vat: Float!
  isSaleWithPrescription: Boolean!
  valueCountRound: Float!
  paymentType: String!
  exportNoBill: Boolean!
}

然后,我只想添加 2 个值:

      detail: {
        vat: input.vat,
        exportNoBill: input.exportNobill
      },

错误:

is missing the following properties from type 'DocumentDetail': valueCountRound, isSaleWithPrescription, paymentType.ts(2740)

【问题讨论】:

  • 你不能只从界面中排除事物,这就是界面的全部意义。
  • 这里有什么问题?你有一个没有可选属性的定义接口,创建了一个没有所有字段的接口类型的对象,打字稿因此对你生气并抛出错误。这正是应该发生的事情

标签: javascript mongodb types graphql nestjs


【解决方案1】:

谢谢大家!! 我有解决办法

const detailInput = {
      vat: input.vat,
      exportNoBill: input.exportNobill
    } as DocumentDetailInput

detail: DocumentDetailInput

现在我不能只从 DocumentDetailInput 接口中排除东西了!!

【讨论】:

    猜你喜欢
    • 2019-05-19
    • 2021-06-24
    • 2021-08-21
    • 2021-01-05
    • 2019-09-11
    • 2019-08-03
    • 2020-10-31
    • 2019-06-21
    • 2020-09-28
    相关资源
    最近更新 更多