Created
November 17, 2021 21:49
-
-
Save colinbes/06428abc49267772e912b6a4694235f9 to your computer and use it in GitHub Desktop.
Discriminated Unions
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 MyError { | |
| type: "error"; | |
| item: {status: number, msg: string}; | |
| } | |
| interface MyNums { | |
| type: "mynums"; | |
| item: number[]; | |
| } | |
| interface MyNum { | |
| type: "mynum"; | |
| item: number; | |
| } | |
| type Generic = MyError | MyNum | MyNums | |
| let test: Generic = { | |
| type: "error", | |
| item: {status: 10, msg: 'hello'} | |
| } | |
| let test1: Generic = { | |
| type: "mynum", | |
| item: 1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment