[英]ESLint: Unsafe assignment of an `any` and Unsafe call of an `any` typed value
[英]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.