From 96f13e15cab52f577fe8e6ba1388f776c89ee9eb Mon Sep 17 00:00:00 2001 From: Jonas Kello Date: Fri, 19 Apr 2019 19:00:03 +0200 Subject: [PATCH] Add CompatPromise conditional type --- .../oidc/js/src/main/resources/keycloak.d.ts | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/adapters/oidc/js/src/main/resources/keycloak.d.ts b/adapters/oidc/js/src/main/resources/keycloak.d.ts index 9fb84e9b3b..ab7878b492 100644 --- a/adapters/oidc/js/src/main/resources/keycloak.d.ts +++ b/adapters/oidc/js/src/main/resources/keycloak.d.ts @@ -26,7 +26,7 @@ export = Keycloak; * Creates a new Keycloak client instance. * @param config Path to a JSON config file or a plain config object. */ -declare function Keycloak(config?: string|{}): Keycloak.KeycloakInstance; +declare function Keycloak(config?: string|{}): Keycloak.KeycloakInstance; declare namespace Keycloak { type KeycloakAdapterName = 'cordova' | 'cordova-native' |'default' | any; @@ -244,11 +244,19 @@ declare namespace Keycloak { // export interface KeycloakUserInfo {} + /** + * Conditional CompatPromise type in order to support + * both legacy promises and native promises as return types. + */ + type PromiseType = KeycloakPromiseType | undefined; + type CompatPromise = + TPromiseType extends KeycloakPromiseType ? Promise : KeycloakPromise; + /** * A client for the Keycloak authentication server. * @see {@link https://keycloak.gitbooks.io/securing-client-applications-guide/content/topics/oidc/javascript-adapter.html|Keycloak JS adapter documentation} */ - interface KeycloakInstance { + interface KeycloakInstance { /** * Is true if the user is authenticated, false otherwise. */ @@ -413,32 +421,32 @@ declare namespace Keycloak { * @param initOptions Initialization options. * @returns A promise to set functions to be invoked on success or error. */ - init(initOptions: KeycloakInitOptions): KeycloakPromise; + init(initOptions: KeycloakInitOptions): CompatPromise; /** * Redirects to login form. * @param options Login options. */ - login(options?: KeycloakLoginOptions): KeycloakPromise; + login(options?: KeycloakLoginOptions): CompatPromise; /** * Redirects to logout. * @param options Logout options. * @param options.redirectUri Specifies the uri to redirect to after logout. */ - logout(options?: any): KeycloakPromise; + logout(options?: any): CompatPromise; /** * Redirects to registration form. * @param options Supports same options as Keycloak#login but `action` is * set to `'register'`. */ - register(options?: any): KeycloakPromise; + register(options?: any): CompatPromise; /** * Redirects to the Account Management Console. */ - accountManagement(): KeycloakPromise; + accountManagement(): CompatPromise; /** * Returns the URL to login form. @@ -490,7 +498,7 @@ declare namespace Keycloak { * alert('Failed to refresh the token, or the session has expired'); * }); */ - updateToken(minValidity: number): KeycloakPromise; + updateToken(minValidity: number): CompatPromise; /** * Clears authentication state, including tokens. This can be useful if @@ -517,11 +525,11 @@ declare namespace Keycloak { * Loads the user's profile. * @returns A promise to set functions to be invoked on success or error. */ - loadUserProfile(): KeycloakPromise; + loadUserProfile(): CompatPromise; /** * @private Undocumented. */ - loadUserInfo(): KeycloakPromise<{}, void>; + loadUserInfo(): CompatPromise; } }