【问题标题】:WebStorm: Argument type this is not assignable to parameter type ObjectConstructorWebStorm:参数类型不能分配给参数类型 ObjectConstructor
【发布时间】:2019-06-09 17:13:57
【问题描述】:

当我在 TypeScript 中使用以下构造函数时,我收到错误 Argument type this is not assignable to parameter type ObjectConstructor。但是 CLI 没有显示错误。代码对我来说看起来不错 (syntax)。这是错误的错误吗?

export class Store{
  oid: string;
  storeNumber: string;
  address: string;

  public constructor(init?: Partial<Store>) {
    Object.assign(this, init);
  }
}

【问题讨论】:

  • 我遇到了同样的问题。当我切换到 VSCode 时,没有错误。看起来像 webstorm 问题

标签: typescript webstorm


【解决方案1】:

这已被记录为WebStorm bug。 (谢谢@lena)。

在发布修复之前,可以通过将以下注释放在包含误报的行上方来禁止检查:

// noinspection TypeScriptValidateTypes

【讨论】:

    猜你喜欢
    • 2021-01-05
    • 2018-12-26
    • 2021-06-19
    • 2021-12-13
    • 2021-08-19
    • 2020-06-25
    • 2019-02-13
    • 2021-11-14
    • 2023-03-09
    相关资源
    最近更新 更多