@typescript eslint/no不安全赋值:"any"值的不安全赋值



我在客户端中使用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.

这是我的代码:

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) => {
//....
})

用户信息在.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不安全赋值:any值的不安全赋值。

这意味着response.data中的属性可能与接口UserInfo中的属性不匹配。

我们可以通过添加来消除这个ESLint warning

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

@typescript eslint/no不安全成员访问:不安全的成员访问。any值上的值。

根据上述错误,您的UserInfo接口中没有任何value属性。因此,它期望value属性应该存在于接口中。问题将通过将其添加到UserInfo中得到解决。

最新更新