Last active
October 9, 2018 22:23
-
-
Save dewey92/51268f66cedeaa7d083773f67134fe29 to your computer and use it in GitHub Desktop.
Intersection & Union Type
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 characters
| /* Intersection type */ | |
| interface Goku { | |
| withKamehameha: boolean; | |
| } | |
| interface Bejita { | |
| sayKakarot: boolean; | |
| } | |
| type Gogeta = Goku & Bejita; | |
| const gogeta: Gogeta = { | |
| withKamehameha: true, | |
| sayKakarot: true, | |
| }; // ✅ | |
| /* Union Type */ | |
| type DateOrString = Date | string; | |
| const isSunday = (date: DateOrString) => | |
| (new Date(date)).getDay() === 0; | |
| isSunday('2018-10-08'); // ✅ | |
| isSunday(new Date('2018-10-08')); // ✅ | |
| isSunday(999); // ❌ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment