gpt4 book ai didi

typescript - 如何解决 "Unsafe call of an ` 任何键入的值。”在 Eslint 中?

转载 作者:行者123 更新时间:2023-12-05 04:31:09 25 4
gpt4 key购买 nike

尝试遍历数组时出现错误。在我的 ForEach 中使用条件时,出现以下错误:

(parameter) treat: {
[x: string]: unknown;
}
Object is of type 'unknown'.

Unsafe call of an `any` typed value.

在最终生成此错误的函数中:

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 应该知道什么样的数组数据是

关于typescript - 如何解决 "Unsafe call of an ` 任何键入的值。”在 Eslint 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71888789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com