繁体   English   中英

如何解决“对 `any` 类型值的不安全调用。” 在埃斯林特?

[英]How to solve "Unsafe call of an `any` typed value." in Eslint?

尝试遍历数组时出现错误。 在我的 ForEach 中使用条件时,出现以下错误:

(parameter) treat: {
    [x: string]: unknown;
}
Object is of type 'unknown'.

Unsafe call of an `any` typed value.

在我的 function 中最终生成此错误:

const companies = ref<HttpState>({
  data: [],
  meta: {},
  loading: false,
})

function getRowsNumberCount(filter: string, totalPages: number | undefined){
  if(!filter){
    return totalPages
  }
  let count = 0

  companies.value.data.forEach(treat => {    

    if(treat.name.includes(filter)){
      ++count
    }
  })
  return count
}

我是 typescript 的新手,但我相信这可能与我的数据输入有关,我已经进行了一些更改,但没有成功。
这是数据类型:

export type PaginationResponse<T = Record<string, unknown>[]> = { meta: Meta, data: T}

export type HttpState = PaginationResponse & { loading: boolean }
type Treat = { name: string }

const companies = ref<HttpState<Treat>>({
  data: [],
  meta: {},
  loading: false,
})

export type PaginationResponse<T = Record<string, unknown>[]> = { meta: Meta, data: T}

export type HttpState<T> = PaginationResponse<T> & { loading: boolean }

现在typescript应该知道数组数据是什么样的了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM