小编rac*_*wan的帖子

类型“string | ”上不存在属性“forEach” 细绳[]'

我有这个代码

  @Where(
    ['owner', 'Manager', 'Email', 'productEmail', 'Region'],
    (keys: string[], values: unknown) => {
      const query = {};

      keys.forEach((k: string) => {            
    }
  )
Run Code Online (Sandbox Code Playgroud)

当我启用类型检查的严格规则时,它会抱怨

Argument of type '(keys: string[], values: unknown) => {}' is not assignable to parameter of type '(key: string | string[], values: unknown) => unknown'.
  Types of parameters 'keys' and 'key' are incompatible.
    Type 'string | string[]' is not assignable to type 'string[]'.
      Type 'string' is not assignable to type 'string[]'.ts
Run Code Online (Sandbox Code Playgroud)

当我将按键类型更改为(keys: string | string[], values: …

type-conversion typescript

0
推荐指数
1
解决办法
8670
查看次数

标签 统计

type-conversion ×1

typescript ×1