Union of generic variants
See original GitHub issueIt would be great if unionize could support union of generic variants
I’m using a generic interface in one of my projects to represent generic fetch status
export interface Fetch<T> {
results: T[]
finished: boolean
}
and I want it to become
export interface FetchLoading {
type: 'loading'
}
export interface FetchSuccess<T> {
type: 'success'
results: T[]
finished: boolean
}
export interface FetchSuccessWithErrors<T> {
type: 'successWithErrors'
results: T[]
finished: boolean
errors: string[]
}
export interface FetchError {
type: 'error'
reason: string
}
And I would create an union type which could be consumed by a UI component showing the fetch status according to its type.
How could we achieve that with unionize?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Handbook - Unions and Intersection Types - TypeScript
An intersection type combines multiple types into one. This allows you to add together existing types to get a single type that has...
Read more >typescript - Discriminated Union of Generic type - Stack Overflow
The problem. Type narrowing in discriminated unions is subject to several restrictions: No unwrapping of generics.
Read more >Unions and interfaces - Apollo GraphQL Docs
Unions and interfaces are abstract GraphQL types that enable a schema field to return one of multiple object types. Union type.
Read more >Custom Types · An Introduction to Elm
Note: Custom types used to be referred to as “union types” in Elm. Names from other communities include tagged ... The UserStatus type...
Read more >TypeScript Fireworks: Union, Intersection and Variance
Give two types A and B , when put in a union A | B , a looser type is created. If we...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey, I was thinking on that problem a lot and finally shipped a version that Im comfortable with: https://github.com/twop/ts-union
Conceptually I have a special token type
Generic
and I replace it with an actual type likestring
at the moment of construction.Might be applicable to
unionize
as well 😃Yeah, I don’t see any reason to make it more verbose than it has to be.
Hmm, yeah, I wonder if we want to enforce that they pass a
value
property or just treat it as implied.