typescript-cheatsheets/react

[Advanced] error in documentation

Closed this issue · 1 comments

Type Guarding: Sometimes Union Types solve a problem in one area but create another downstream. If A and B are both object types, A | B isn't "either A or B", it is "A or B or both at once", which causes some confusion if you expected it to be the former. Learn how to write checks, guards, and assertions (also see the Conditional Rendering section below). For example:

This is not true. A | B is indeed A or B. For instance, if type Foo = { a: number } | { b: string }, in a: Foo = { a: 1, b: 'two' }, a would be "both at once" but that value is not assignable to type Foo. It's possible you're thinking of intersection types.

Hey! I'd like to fix this documentation error.
Can I submit a PR for this?

I'll update the text to correctly explain that A | B
means 'either A or B' (not both).