I’m working with a library that uses the following type definition:
export interface Auth0ContextInterface<TUser extends User = User> extends AuthState<TUser> {
getAccessTokenSilently: {
(options: GetTokenSilentlyOptions & { detailedResponse: true }): Promise<
GetTokenSilentlyVerboseResponse
>;
(options?: GetTokenSilentlyOptions): Promise<string>;
(options: GetTokenSilentlyOptions): Promise<
GetTokenSilentlyVerboseResponse | string
>;
};
...
Can someone explain what the getAccessTokenSilently definition means? I assumed that it was another way of joining multiple types, but none of these work in the codebase I’m working on.
Help would be much appreciated!
>Solution :
It a function overload type definition,
The getAccessTokenSilently method on oyur object has 3 different definitions :
(options: GetTokenSilentlyOptions & { detailedResponse: true }): Promise< GetTokenSilentlyVerboseResponse>(options?: GetTokenSilentlyOptions): Promise<string>;(options: GetTokenSilentlyOptions): Promise< GetTokenSilentlyVerboseResponse | string>;