下面的代码为 生成以下 TypeScript 错误:response.accessToken
TS2339:属性“accessToken”在类型“void |上不存在TokenResponse'.
import * as Msal from '@azure/msal-browser'
export async function getTokenPopup(request: Msal.TokenExchangeParameters) {
return await auth.acquireTokenSilent(request).catch(async () => {
return await auth.acquireTokenPopup(request).catch((error) => {
console.log('login with popup failed: ', error)
})
})
}
const getGraphDetails = async (
uri: string,
scopes: Msal.TokenExchangeParameters,
axiosConfig?: AxiosRequestConfig
) => {
return getTokenPopup(scopes).then((response) => {
return callGraph(uri, response.accessToken, axiosConfig)
})
}
当检查 TokenResponse 的 TS 定义时,它清楚地表明该属性在对象上可用:accessToken
export type TokenResponse = AuthResponse & {
uniqueId: string;
tenantId: string;
scopes: Array<string>;
tokenType: string;
idToken: string;
idTokenClaims: StringDict;
accessToken: string;
refreshToken: string;
expiresOn: Date;
account: Account;
};
我做错了什么?
慕妹3242003
相关分类