Skip to content

Hex Colors error with TS2590: Expression produces a union type that is too complex to represent #59015

Closed as not planned
@AtomicGamer9523

Description

@AtomicGamer9523

🔎 Search Terms

ts(2590), Expression produces a union type that is too complex to represent., HexTypes

🕗 Version & Regression Information

This is an error that typescript throws when I try to build it, as well as the LSP complains. It raises the error ts(2590), Expression produces a union type that is too complex to represent

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAEhAeBhAFgQwE5QLxQEQAZcoAfPARiNNwCZK8BmO3AFiYFYmA2JgdiYA4mATiYBBJgCEmiJgBEmAUSYAxXAG4AUKEiwE9RAHsANgcw4ABgGIAJAG84SNOgC+dhygyv7CDy-ObtaAdOQxMzKCs3Hycvdxiox08E31jopO9EvwDwIIR+UNNsCJsMlOT40oq49OqXcpq0usrPfw0NBDBTYChA3SRjQpwHfQHMUmCCsb780bUgA

💻 Code

type HexChar = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "A" | "B" | "C" | "D" | "E" | "F";
type Hex3Color = `#${HexChar}${HexChar}${HexChar}`;
type Hex6Color = `#${HexChar}${HexChar}${HexChar}${HexChar}${HexChar}${HexChar}`;
type Hex8Color = `#${HexChar}${HexChar}${HexChar}${HexChar}${HexChar}${HexChar}${HexChar}${HexChar}`;

export type HexColor = Hex3Color | Hex6Color | Hex8Color;

🙁 Actual behavior

The type of HexColor should be well defined and accessible. As well as there shouldn't be any errors.

🙂 Expected behavior

The type of HexColor is any, and there are errors.

Additional information about the issue

It seems that also Deno is affected (I first discovered it using Deno). I tried switching to plain TS, still raises errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions