Typescript type for appState?

Hi,

I’m using the <Auth0Context.Provider> to manage the redirect callback with this function:

const onRedirectCallback = (appState: any): void => {
history.push(
appState && appState.targetUrl
? appState.targetUrl
: window.location.pathname
);
};

Typescript throws an error: Unexpected any. Specify a different type @typescript-eslint/no-explicit-any

If I create an interface for this:

interface AppStateInterface {
targetUrl: string;
}

I get this error:
TS2322: Type ‘(appState: AppStateInterface) => void’ is not assignable to type ‘(appState?: {}) => void’.
Types of parameters ‘appState’ and ‘appState’ are incompatible.
Type ‘{} | undefined’ is not assignable to type ‘AppStateInterface’.
Type ‘undefined’ is not assignable to type ‘AppStateInterface’.

How to resolve? Is there a way I can import the type from the auth0-spa-js library maybe?

Thanks

1 Like

(in addition, appState: object doesn’t work because I call the targetUrl property on appState)