【发布时间】:2022-07-08 16:06:54
【问题描述】:
我使用 @azure/msal-react 和 @azure/msal-browser 在 React with Typescript 中实现身份验证。
我的问题是 TypeScript 知道 event.payload 的类型为 EventPayload(联合),但是它不允许我使用 instanceof 运算符检查确切的类型(例如 AuthenticationResult)。
如何查看event.payload 的确切类型?
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)
...
}
}
...
});
【问题讨论】:
标签: javascript typescript msal