我在客户端使用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) => {
//....
})
UserInfo 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
}
发布于 2022-02-23 07:48:18
@typescript-eslint/no-不安全-赋值:
any
值的不安全分配。
这意味着response.data
中的属性可能与接口UserInfo
的属性不匹配。
我们可以通过添加类似于ESLint warning
的来摆脱这个。
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@typescript-eslint/no-不安全-成员访问:
any
值上的不安全成员访问.value。
根据上面的错误,您的value
接口中没有任何UserInfo
属性。因此,它期望value
属性应该在接口中。通过将其添加到UserInfo
中,问题将得到解决。
https://stackoverflow.com/questions/71232812
复制相似问题