Skip to content

SimplifyUnion #1174

Description

@benzaria

Type description + examples

A type that simplify a union. When merging 2 of more unions TS hide the underline types.
use case:

type U1 = 5 | ['b'] | symbol
type U2 = null | '2' | {foo: 'bar'}

type U3 = U1 | U2
//	  ^? U3 = U1 | U2 

type U4 = SimplifyUnion<U3>
//	  ^? U4 = symbol | 5 | "2" | ["b"] | {foo: "bar"} | null

Type source

type SimplifyUnion<T> = {[K in T as string]: K}[string]

Search existing types and issues first

  • I tried my best to look for it

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions