Skip to content
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

DOCS: wrong/confusing explanation of union of objects #3289

Open
melogo5 opened this issue Dec 23, 2024 · 0 comments
Open

DOCS: wrong/confusing explanation of union of objects #3289

melogo5 opened this issue Dec 23, 2024 · 0 comments

Comments

@melogo5
Copy link

melogo5 commented Dec 23, 2024

Page URL: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types

Issue: wrong/confusing explanation of union of objects.
Info block at the end of "Union Types" section states:

It might be confusing that a union of types appears to have the intersection of those types’ properties. This is not an accident - the name union comes from type theory. The union number | string is composed by taking the union of the values from each type. Notice that given two sets with corresponding facts about each set, only the intersection of those facts applies to the union of the sets themselves. For example, if we had a room of tall people wearing hats, and another room of Spanish speakers wearing hats, after combining those rooms, the only thing we know about every person is that they must be wearing a hat.

Example of code dependant on 2 principles from the explanation:

a union of types appears to have the intersection of those types’ properties>

the only thing we know about every person is that they must be wearing a hat>

Image

But it gives us an error:
Image

So, working example for the provided explanation look like this. But i see no connection between following code and provided explanation in doc:
Image

Proposals:
Edit info block in doc or remove it

Simillar topic about how union types actually works microsoft/TypeScript#20863

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant