Skip to content

Instantly share code, notes, and snippets.

@tatat
Last active June 4, 2018 12:41
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 tatat/4eb37fbc75e4d5eec550b50aa45e393e to your computer and use it in GitHub Desktop.
Save tatat/4eb37fbc75e4d5eec550b50aa45e393e to your computer and use it in GitHub Desktop.
sample.ts
type ResponseBase = {};
type SuccessResponse = ResponseBase & { data: any };
type ErrorResponse = ResponseBase & { error: string };
type Callback = (response: SuccessResponse | ErrorResponse) => void;
function call(callback: Callback) {
callback(<SuccessResponse> { data: {} });
}
call(response => {
if ('error' in response) {
console.log(response.error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment