Skip to content

Instantly share code, notes, and snippets.

@bennycode
Last active August 14, 2022 22:30
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 bennycode/7cacbf64ddeaf6395c16927375331d0f to your computer and use it in GitHub Desktop.
Save bennycode/7cacbf64ddeaf6395c16927375331d0f to your computer and use it in GitHub Desktop.
Never Type
interface StreamResponse {
status: StreamStatus;
}
enum StreamStatus {
IDLE,
ONLINE,
OFFLINE,
}
function handleResponse(response: StreamResponse): void {
switch (response.status) {
case StreamStatus.ONLINE:
console.log('You are online.');
break;
case StreamStatus.OFFLINE:
console.log('You are offline.');
break;
default:
const status: never = response.status;
throw new Error(`Unknown status "${status}"!`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment