下面的 ts 代码
const userInfo = await UserService.getUserInfoWithToken(token, isPat)
const { spaceUserID, displayName } = userInfo
const session = <AuthenticationSession>{
account: {
id: spaceUserID.toString(),
label: displayName,
},
id: `${this.providerId}-${userInfo.spaceUserID}`,
accessToken: token,
scopes: this.ensureScopes(null),
}
在执行 eslint 时报下面2个错误
Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
请问如何解决?
getUserInfoWithToken 方法的主要实现代码
export async function getUserInfoWithToken(token: string, isPat: boolean): Promise<UserInfo> {
const req = await fetch(url, {
headers: {
authorization: `Bearer ${token}`,
'content-type': 'application/json',
'authorization-type': isPat ? 'pat' : '',
},
})
return (await req.json()) as UserInfo
}
UserInfo 接口的实现代码
export interface UserInfo {
userId: string
spaceUserID: number
displayName: string
}
将 id: spaceUserID.toString()
改为 id: new Number(spaceUserID).toString()
解决了