Add TaggedUnion type#566
Merged
sindresorhus merged 2 commits intosindresorhus:mainfrom Mar 13, 2023
Merged
Conversation
sindresorhus
requested changes
Mar 7, 2023
| @@ -0,0 +1,41 @@ | |||
| /** | |||
| Utility type to create a tagged union with given tag | |||
Owner
There was a problem hiding this comment.
The first sentence in this file should be the same as the readme.
Contributor
Author
There was a problem hiding this comment.
Good point! I fixed this :)
| type EventMessage = TaggedUnion< | ||
| 'tag', | ||
| { | ||
| NavigationStateChanged: { |
Contributor
Author
There was a problem hiding this comment.
I reformatted the comment with xo. Should have tabs now :)
| ``` | ||
| import type {TaggedUnion} from 'type-fest'; | ||
|
|
||
| type EventMessage = TaggedUnion< |
Owner
There was a problem hiding this comment.
I think it would be useful to show the same an example of the same just without this type. So you can clearly see how it simplifies making a tagged union.
Contributor
Author
There was a problem hiding this comment.
True! I added an example without use of this utility.
10abdd4 to
91491b1
Compare
odaiwa
approved these changes
Mar 10, 2023
1b1805c to
8faf32d
Compare
- use tab-intendation - Add example to comment - Improve doc comment
8faf32d to
4b07661
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Example use case:
An union type like this
Can be expressed like this: