Skip to content

Commit

Permalink
Make Working with Union Types clear and concise
Browse files Browse the repository at this point in the history
  • Loading branch information
sarscode authored Jan 12, 2022
1 parent ee9cab6 commit cde0370
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ printId({ myID: 22342 });
It's easy to _provide_ a value matching a union type - simply provide a type matching any of the union's members.
If you _have_ a value of a union type, how do you work with it?

TypeScript will only allow you to do things with the union if that thing is valid for _every_ member of the union.
TypeScript will only allow an operation if it is valid for _every_ member of the union.
For example, if you have the union `string | number`, you can't use methods that are only available on `string`:

```ts twoslash
Expand Down

0 comments on commit cde0370

Please sign in to comment.