Created
October 18, 2022 09:50
-
-
Save Cerber-Ursi/6ca1b3a6f456732b2d444d4a085fef91 to your computer and use it in GitHub Desktop.
https://stackoverflow.com/questions/74105053/typescript-multiple-functions-with-distinct-parameters - reproduction attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class InitEventArgs {}; | |
export class ResetEventArgs {}; | |
export class ItemsChangedEventArgs { | |
public added: ReadonlyArray<any>; | |
public removed: ReadonlyArray<any>; | |
constructor(added?: ReadonlyArray<any>, removed?: ReadonlyArray<any>) { | |
this.added = added || []; | |
this.removed = removed || []; | |
} | |
}; | |
export type ApiEventType = 'init' | 'reset' | 'itemsChanged'; | |
export type ApiEventHandler = (() => void) | |
| ((e:CustomEvent<InitEventArgs>) => void) | |
| ((e:CustomEvent<ResetEventArgs>) => void) | |
| ((e:CustomEvent<ItemsChangedEventArgs>) => void); | |
export interface IApi { | |
// ... | |
addEventListener: (type: ApiEventType, listener: ApiEventHandler) => void; | |
removeEventListener: (type: ApiEventType, listener: ApiEventHandler) => void; | |
// ... | |
} | |
const api: IApi = {} as any; // no implementation required | |
api.addEventListener('itemsChanged', (e:CustomEvent<ItemsChangedEventArgs>) => { /* ... */ }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment