Created
January 15, 2020 13:17
-
-
Save markmur/6f552cfe9c2a0d05fbabe46d69c07619 to your computer and use it in GitHub Desktop.
Function overloading
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 enum Events { | |
LOGIN = 'login', | |
LOGOUT = 'logout' | |
} | |
interface LoginPayload { | |
login: true | |
} | |
interface LogoutPayload { | |
logout: true | |
} | |
export function dispatch(event: Events.LOGIN, payload: LoginPayload): void | |
export function dispatch(event: Events.LOGOUT, payload: LogoutPayload): void | |
export function dispatch(event: Events, payload: object) { | |
switch (event) { | |
// do something based on event | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment