简体   繁体   English

@typescript-eslint/no-unsafe-assignment: `any` 值的不安全赋值

[英]@typescript-eslint/no-unsafe-assignment: Unsafe assignment of an `any` value

I am using TypeScript in my client, when i run my application, there are two errors show as follow:我在我的客户端中使用 TypeScript,当我运行我的应用程序时,有两个错误显示如下:

@typescript-eslint/no-unsafe-assignment: Unsafe assignment of an `any` value.

@typescript-eslint/no-unsafe-member-access: Unsafe member access .value on an `any` value.

Here is my code:这是我的代码:

const userInfo = ref({} as UserInfo) // first error

$f.axios
    .get<UserInfo>('/comm/auth/get-my-info')
    .then((result) => {
      userInfo.value = result.data // second error
    })
    .catch((err) => {
      //....
    })

UserInfo in.ts:用户信息 in.ts:

export interface UserInfo {
  userName: string
  realName: string
  password: string | null
  email: string | null
  mobilePhone: string | null
  appToken: string | null
  internalTags: string | null
  enabledState: boolean
  isApiUser: boolean
  createDt: Date
  createP: string
  createPn: string | null
  updateDt: Date
  updateP: string
  updatePn: string | null
  firstLogin: true
  passwordExpiresDt: Date | null
  rolesString: string | null
  userRoleIds: number[] | null
}

@typescript-eslint/no-unsafe-assignment: Unsafe assignment of an any value. @typescript-eslint/no-unsafe-assignment: any值的不安全赋值。

This means that the properties in response.data might not match the ones of the interface UserInfo .这意味着response.data中的属性可能与接口UserInfo的属性不匹配。

We can get rid of this ESLint warning by adding like :我们可以通过添加以下内容来摆脱这个ESLint warning

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment

@typescript-eslint/no-unsafe-member-access: Unsafe member access.value on an any value. @typescript-eslint/no-unsafe-member-access: any值上的不安全成员 access.value。

As per the above error, You don't have any value property in your UserInfo interface.根据上述错误,您的UserInfo界面中没有任何value属性。 Hence, it is expecting value property should be there in the interface.因此,它value属性应该存在于界面中。 Issue will get resolve by adding it in the UserInfo .问题将通过将其添加到UserInfo中得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么缓冲区分配会触发不安全的分配错误? - Why is Buffer assignment triggering an unsafe assignment error? eslint 缩进和@typescript-eslint/indent 冲突 - eslint indent and @typescript-eslint/indent conflict 对 Typescript function 中的 return 语句不安全地使用“any”类型的表达式 - Unsafe use of expression of type 'any' for return statements in Typescript function ESLint 与 eslint-plugin-import 和 typescript-eslint 冲突 - ESLint conflicts with eslint-plugin-import and typescript-eslint 纱线 - 错误找不到与“5.31.0”匹配的“@typescript-eslint/type-utils”的任何版本 - Yarn - error Couldn't find any versions for "@typescript-eslint/type-utils" that matches "5.31.0" 找不到与 @typescript-eslint/scope-manager@4.22.1 匹配的版本 - No matching version found for @typescript-eslint/scope-manager@4.22.1 添加规则时出现 Eslint 错误 @typescript-eslint/interface-name-prefix - Eslint erro when adding rule @typescript-eslint/interface-name-prefix @typescript-eslint/eslint-plugin@2.3.2:引擎“节点”与此模块不兼容 - @typescript-eslint/eslint-plugin@2.3.2: The engine “node” is incompatible with this module 资源URL上下文中使用的不安全值 - unsafe value used in a resource URL context Typescript 节点快速路由器和第二个参数。 Typescript-eslint/无误用承诺 - Typescript node express router and second argument. Typescript-eslint/no-misused-promises
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM