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