Skip to content

Conversation

@Aditya-myst
Copy link
Contributor

Description

Fixes incorrect explanation of TypeScript union types in the documentation.

The Issue

The documentation incorrectly stated that A | B means "A or B or both at once".
This is incorrect - union types represent exactly one type or the other, not both simultaneously.

Changes Made

  • Corrected the explanation to clarify that A | B means "either A or B"
  • Added clarification about intersection types A & B for "both at once" scenario
  • Added note about property access requiring type guards
  • Updated docs/basic/troubleshooting/types.md (README.md will auto-generate from this)

Example

type Foo = { a: number } | { b: string }
const invalid: Foo = { a: 1, b: 'two' } // ❌ Error - not assignable  
const valid: Foo = { a: 1 }             // ✅ Correct

…on from 'both at once' to 'either A or B'- Added clarification about intersection types (A & B) - Updated docs/basic/troubleshooting/types.md

Fixes typescript-cheatsheets#787
@filiptammergard
Copy link
Collaborator

Thanks!

@filiptammergard filiptammergard merged commit 911f928 into typescript-cheatsheets:main Oct 28, 2025
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants