You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
But it gives us an error:
So, working example for the provided explanation look like this. But i see no connection between following code and provided explanation in doc:
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:
Example of code dependant on 2 principles from the explanation:
But it gives us an error:
So, working example for the provided explanation look like this. But i see no connection between following code and provided explanation in doc:
Proposals:
Edit info block in doc or remove it
Simillar topic about how union types actually works microsoft/TypeScript#20863
The text was updated successfully, but these errors were encountered: