Ant*_*ony 7 typescript eslint vue.js
我在尝试循环数组时遇到错误。当在 ForEach 中使用条件时,出现以下错误:
(parameter) treat: {
[x: string]: unknown;
}
Object is of type 'unknown'.
Unsafe call of an `any` typed value.
Run Code Online (Sandbox Code Playgroud)
在我的函数中最终生成此错误:
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
}
Run Code Online (Sandbox Code Playgroud)
我是打字稿的新手,但我相信这可能与我的数据输入有关,我已经做了一些更改,但还没有成功。
这是数据输入:
export type PaginationResponse<T = Record<string, unknown>[]> = { meta: Meta, data: T}
export type HttpState = PaginationResponse & { loading: boolean }
Run Code Online (Sandbox Code Playgroud)
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 }
Run Code Online (Sandbox Code Playgroud)
现在打字稿应该知道数组数据是什么类型
| 归档时间: |
|
| 查看次数: |
25063 次 |
| 最近记录: |