Skip to content

Instantly share code, notes, and snippets.

@markmur
Created January 15, 2020 13:17
Show Gist options
  • Save markmur/6f552cfe9c2a0d05fbabe46d69c07619 to your computer and use it in GitHub Desktop.
Save markmur/6f552cfe9c2a0d05fbabe46d69c07619 to your computer and use it in GitHub Desktop.
Function overloading
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