types-as-sets
Think of Types as Sets of Values
Overview
A type is a set of possible values. Assignability means subset.
Understanding types as sets helps you reason about unions, intersections, extends, and never. This mental model makes TypeScript's behavior intuitive.
When to Use This Skill
- Confused why
A & Bhas MORE properties thanAorB - Don't understand why
extendsmeans "subset" - Reasoning about union and intersection types
- Working with
neverorunknowntypes - Debugging "not assignable to" errors
The Iron Rule
More from marius-townhouse/effective-typescript-skills
precise-any-variants
Use when forced to use any. Use when any is too broad. Use when function types need any.
86narrow-any-scope
Use when any is unavoidable. Use when working with untyped libraries. Use when silencing specific type errors.
35tsdoc-comments
Use when documenting public APIs. Use when writing library code. Use when using JSDoc-style comments. Use when generating documentation. Use when explaining complex types.
34exhaustiveness-checking
Use when handling tagged unions. Use when adding new cases to discriminated unions. Use when switch statements must cover all cases.
13code-gen-independent
Use when confused about types at runtime. Use when trying to use instanceof with interfaces. Use when type errors don't prevent JavaScript output.
12tsconfig-options
Use when setting up a TypeScript project. Use when confused by type checking behavior. Use when strict mode causes unexpected errors.
11