[英]How to solve "Unsafe call of an `any` typed value." in Eslint?
I'm getting an error when trying to loop through an array.尝试遍历数组时出现错误。 When using a condition inside my ForEach I get the following error:
在我的 ForEach 中使用条件时,出现以下错误:
(parameter) treat: {
[x: string]: unknown;
}
Object is of type 'unknown'.
Unsafe call of an `any` typed value.
Inside my function that ends up generating this error:在我的 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
}
I'm new to typescript, but I believe it may be something with the typing of my data, I've already made some changes but I haven't had success.我是 typescript 的新手,但我相信这可能与我的数据输入有关,我已经进行了一些更改,但没有成功。
Here is the data typing:这是数据类型:
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 }
Now typescript should know what kind of array data is现在typescript应该知道数组数据是什么样的了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.