Created
March 27, 2017 18:40
-
-
Save devmobasa/ba763b1c91d28acdac08efee547dfbb3 to your computer and use it in GitHub Desktop.
Union Types in TypeScript - Interfaces
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
| interface IStudent { | |
| id: string; | |
| age: number; | |
| } | |
| interface IWorker { | |
| companyId: string; | |
| } | |
| type IUnionType = IStudent | IWorker; | |
| let p: IUnionType = { | |
| id: 'ID3241', | |
| age: 21 | |
| }; | |
| // p = 3; // Type '3' is not assignable to type 'IUnionType' | |
| p = { | |
| companyId: 'cid993' | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment