Created
August 27, 2017 20:38
-
-
Save asolove/ff59b0ce95b355d864a9d78f306e5dc5 to your computer and use it in GitHub Desktop.
Revisions
-
asolove created this gist
Aug 27, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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() } }