Skip to content

Union of generic variants  #43

Description

@Stouffi

It 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions