The code below generates the following TypeScript error for the response.accessToken:
TS2339: Property 'accessToken' does not exist on type '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)
})
}
When checking the TS definition of TokenResponse it clearly states that the property accessToken is available on the object:
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;
};
What am I doing wrong?
