I'm getting an error when trying to loop through an array. When using a condition inside my ForEach I get the following error:
(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:
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.