元素隐式具有 'any' 类型,因为类型 '"' 的表达式不能用于索引类型 '{}'

时间:2021-03-03 04:36:55

标签: typescript type-conversion tsconfig

我有以下代码

错误场景 1

@Where(['compuWarnings'], (keys: string | string[], values: unknown) => {
    if (values['compuwarnings'].length === 1) {
      const [creator] = values['compuwarnings'];
      return {
        nonUnique: {
          [Op.like]: `%${creator}%`
        }
      };
    }

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

enter image description here

Element implicitly has an 'any' type because expression of type '"compuWarnings"' can't be used to index type '{}'.
  Property 'compuWarnings' does not exist on type '{}'.ts(7053)

当我将 values 类型设为 any 时,警告消失了,这会引发 es lint 警告。

错误场景 2

enter image description here

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.

有人可以在不使用任何类型的情况下帮助解决此问题吗

0 个答案:

没有答案