diff --git a/src/cache.ts b/src/cache.ts index be9bf6688f..b8b1e89818 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -71,13 +71,16 @@ export class ListWatch implements ObjectCache, In this._stop(); } - public on(verb: 'add' | 'update' | 'delete' | 'change', cb: ObjectCallback): void; - public on(verb: 'error' | 'connect', cb: ErrorCallback): void; - public on(verb: string, cb: any): void { + public on(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback): void; + public on(verb: ERROR | CONNECT, cb: ErrorCallback): void; + public on( + verb: ADD | UPDATE | DELETE | CHANGE | ERROR | CONNECT, + cb: ObjectCallback | ErrorCallback, + ): void { if (verb === CHANGE) { - this.on('add', cb); - this.on('update', cb); - this.on('delete', cb); + this.on(ADD, cb); + this.on(UPDATE, cb); + this.on(DELETE, cb); return; } if (this.callbackCache[verb] === undefined) { diff --git a/src/informer.ts b/src/informer.ts index eb67bbd8db..714ff4fe57 100644 --- a/src/informer.ts +++ b/src/informer.ts @@ -9,19 +9,27 @@ export type ListCallback = (list: T[], ResourceVersi export type ListPromise = () => Promise>; // These are issued per object -export const ADD: string = 'add'; -export const UPDATE: string = 'update'; -export const CHANGE: string = 'change'; -export const DELETE: string = 'delete'; +export const ADD = 'add'; +export type ADD = typeof ADD; +export const UPDATE = 'update'; +export type UPDATE = typeof UPDATE; +export const CHANGE = 'change'; +export type CHANGE = typeof CHANGE; +export const DELETE = 'delete'; +export type DELETE = typeof DELETE; // This is issued when a watch connects or reconnects -export const CONNECT: string = 'connect'; +export const CONNECT = 'connect'; +export type CONNECT = typeof CONNECT; // This is issued when there is an error -export const ERROR: string = 'error'; +export const ERROR = 'error'; +export type ERROR = typeof ERROR; export interface Informer { - on(verb: string, fn: ObjectCallback): void; - off(verb: string, fn: ObjectCallback): void; + on(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback): void; + on(verb: ERROR | CONNECT, cb: ErrorCallback): void; + off(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback): void; + off(verb: ERROR | CONNECT, cb: ErrorCallback): void; start(): Promise; stop(): Promise; }