Skip to content

Non-primitive types in unions #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
peter-leonov opened this issue Dec 31, 2024 · 0 comments
Open

Non-primitive types in unions #1

peter-leonov opened this issue Dec 31, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@peter-leonov
Copy link
Owner

tl;dr Non-primitive types in unions are not currently supported, instead please extract the type that is not supported into a separate type replace it with the type alias name:

// before:
type SomeUnion = string | { name: string; id: number }
// after:
type User = { name: string; id: number }
type SomeUnion = string | User

This is not impossible, but would require either an unstable hack or type definition duplication. Both are cumbersome to support for the end user. As far as the workaround is trivial and provides bullet proof readability and stability, for now we go with it.

@peter-leonov peter-leonov added the documentation Improvements or additions to documentation label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant