簡體   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