我在客户端中使用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
中得到解决。