如何解决埃斯林特的"Unsafe call of an `any` typed value."?



尝试通过数组循环时出现错误。当在ForEach中使用条件时,我得到以下错误:

(parameter) treat: {
    [x: string]: unknown;
}
Object is of type 'unknown'.
Unsafe call of an `any` typed value.

在我的函数中,最终产生这个错误:

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
}

我刚接触打字,但我相信这可能是我的数据键入的问题,我已经做了一些改变,但还没有成功。
数据类型如下:

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应该知道数组数据是什么类型的

相关内容

最新更新