Skip to content

Instantly share code, notes, and snippets.

@asolove
Created August 27, 2017 20:38
Show Gist options
  • Select an option

  • Save asolove/ff59b0ce95b355d864a9d78f306e5dc5 to your computer and use it in GitHub Desktop.

Select an option

Save asolove/ff59b0ce95b355d864a9d78f306e5dc5 to your computer and use it in GitHub Desktop.

Revisions

  1. asolove created this gist Aug 27, 2017.
    11 changes: 11 additions & 0 deletions better.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    const checkType = (element: 'a' | 'b' | 'c'): string => {
    switch (element) {
    case 'a':
    return 'first';
    case 'b':
    return 'second';
    default:
    (element: empty) // This cast only succeeds if you've already handled every possible case. Otherwise, you will get a type error
    throw new Error()
    }
    }