From e9142743fa9a4f0663b20ed5179eef529967f619 Mon Sep 17 00:00:00 2001 From: jlau Date: Fri, 15 Mar 2019 10:59:58 -0400 Subject: [PATCH] Improve typings for UserManagerEvents callback signatures --- index.d.ts | 28 ++++++++++++++++++---------- src/UserManagerEvents.js | 8 ++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/index.d.ts b/index.d.ts index fc4e8d09..92c77166 100644 --- a/index.d.ts +++ b/index.d.ts @@ -187,20 +187,28 @@ export interface UserManagerEvents extends AccessTokenEvents { load(user: User): any; unload(): any; - addUserLoaded(callback: (...ev: any[]) => void): void; - removeUserLoaded(callback: (...ev: any[]) => void): void; + addUserLoaded(callback: UserManagerEvents.UserLoadedCallback): void; + removeUserLoaded(callback: UserManagerEvents.UserLoadedCallback): void; - addUserUnloaded(callback: (...ev: any[]) => void): void; - removeUserUnloaded(callback: (...ev: any[]) => void): void; + addUserUnloaded(callback: UserManagerEvents.UserUnloadedCallback): void; + removeUserUnloaded(callback: UserManagerEvents.UserUnloadedCallback): void; - addSilentRenewError(callback: (...ev: any[]) => void): void; - removeSilentRenewError(callback: (...ev: any[]) => void): void; + addSilentRenewError(callback: UserManagerEvents.SilentRenewErrorCallback): void; + removeSilentRenewError(callback: UserManagerEvents.SilentRenewErrorCallback): void; - addUserSignedOut(callback: (...ev: any[]) => void): void; - removeUserSignedOut(callback: (...ev: any[]) => void): void; + addUserSignedOut(callback: UserManagerEvents.UserSignedOutCallback): void; + removeUserSignedOut(callback: UserManagerEvents.UserSignedOutCallback): void; - addUserSessionChanged(callback: (...ev: any[]) => void): void; - removeUserSessionChanged(callback: (...ev: any[]) => void): void; + addUserSessionChanged(callback: UserManagerEvents.UserSessionChangedCallback): void; + removeUserSessionChanged(callback: UserManagerEvents.UserSessionChangedCallback): void; +} + +export namespace UserManagerEvents { + export type UserLoadedCallback = (user: User) => void; + export type UserUnloadedCallback = () => void; + export type SilentRenewErrorCallback = (error: Error) => void; + export type UserSignedOutCallback = () => void; + export type UserSessionChangedCallback = () => void; } export interface UserManagerSettings extends OidcClientSettings { diff --git a/src/UserManagerEvents.js b/src/UserManagerEvents.js index 1c2a2212..47f20008 100644 --- a/src/UserManagerEvents.js +++ b/src/UserManagerEvents.js @@ -60,9 +60,9 @@ export class UserManagerEvents extends AccessTokenEvents { removeUserSignedOut(cb) { this._userSignedOut.removeHandler(cb); } - _raiseUserSignedOut(e) { + _raiseUserSignedOut() { Log.debug("UserManagerEvents._raiseUserSignedOut"); - this._userSignedOut.raise(e); + this._userSignedOut.raise(); } addUserSessionChanged(cb) { @@ -71,8 +71,8 @@ export class UserManagerEvents extends AccessTokenEvents { removeUserSessionChanged(cb) { this._userSessionChanged.removeHandler(cb); } - _raiseUserSessionChanged(e) { + _raiseUserSessionChanged() { Log.debug("UserManagerEvents._raiseUserSessionChanged"); - this._userSessionChanged.raise(e); + this._userSessionChanged.raise(); } }