简体   繁体   English

如何解决“对 `any` 类型值的不安全调用。” 在埃斯林特?

[英]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.

相关问题 ESLint:“any”的不安全分配和“any”类型值的不安全调用 - ESLint: Unsafe assignment of an `any` and Unsafe call of an `any` typed value Typescript Jest 函数的 ESLint 错误(“any”类型值的不安全调用) - Typescript ESLint errors with Jest functions (Unsafe call of an `any` typed value) Typescript:ESLint:任何类型值的不安全返回 @typescript-eslint/no-unsafe-return - Typescript : ESLint : Unsafe return of an any typed value @typescript-eslint/no-unsafe-return 不安全的成员访问<method>在 `any` 值上。 `this` 在编译器项目的 TypeScript 中被键入为 `any`。 如何为 TypeScript 构建 mixin?</method> - Unsafe member access <method> on an `any` value. `this` is typed as `any` in TypeScript for compiler project. How to architect mixins for TypeScript? 元素引用<any> .nativeElement:任何抛出“任何类型值的不安全调用”错误</any> - ElementRef<any>.nativeElement: any throwing "Unsafe call of an any typed value" error 任何值 ESLint 错误的 Typescript 不安全分配 - Typescript Unsafe Assignment of An Any Value ESLint Error @typescript-eslint/no-unsafe-assignment: `any` 值的不安全赋值 - @typescript-eslint/no-unsafe-assignment: Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment:任何值的不安全赋值 - @typescript-eslint/no-unsafe-assignment: Unsafe assignment of an any value Typescript 不安全地返回“任何”类型的值 - Typescript Unsafe return of an `any` typed value 任何值上的 eslint 错误不安全成员访问 ['content-type'] - eslint error Unsafe member access ['content-type'] on an any value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM