Utilizing @azure/msal-react
and @azure/msal-browser
for implementing authentication in a React project with Typescript.
The issue arises when TypeScript identifies event.payload
as type EventPayload
, but does not allow checking the exact type (e.g. AuthenticationResult
) using the instanceof
operator.
How can the exact type of event.payload
be verified?
import {
EventType,
AuthenticationResult,
PublicClientApplication,
} from "@azure/msal-browser";
export declare type EventPayload = AccountInfo | PopupRequest | RedirectRequest | SilentRequest | SsoSilentRequest | EndSessionRequest | AuthenticationResult | PopupEvent | null;
msalInstance.addEventCallback((event) => {
if (event.eventType === EventType.LOGIN_SUCCESS) {
if (event.payload instanceof AuthenticationResult) {
// 'AuthenticationResult' only refers to a type, but is being used as a value here.ts(2693)
...
}
}
...
});