Skip to content

Instantly share code, notes, and snippets.

@alex-okrushko
Last active May 11, 2019 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-okrushko/886ad72a9f1a768bf6dd2dea17fdcc98 to your computer and use it in GitHub Desktop.
Save alex-okrushko/886ad72a9f1a768bf6dd2dea17fdcc98 to your computer and use it in GitHub Desktop.
export const enum LoadingState {
INIT = 'INIT',
LOADING = 'LOADING',
LOADED = 'LOADED',
}
export interface ErrorState {
errorMsg: string;
}
export type CallState = LoadingState | ErrorState;
// Helper function to extract error, if there is one.
export function getError(callState: CallState): string | null {
if ((callState as ErrorState).errorMsg !== undefined) {
return (callState as ErrorState).errorMsg;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment