Binary Arithmetic in TypeScript's Type System
summary
Implements binary arithmetic in TypeScript's type system by encoding bits as 0|1, writing type-level bit flip and type-level bit add operations, mapping those across arrays to form 8‑bit integers and carrying between columns to add two bytes. Shows concrete conditional and mapped generic types, produces an array result for 8‑bit addition, and demonstrates type-level assertions as tests. The surprising part is doing full byte addition (with carries) purely in the type checker.
AI-written summary · about
chapters (17)
- 0:00Intro
- 0:53Language
- 2:05Examples of type descriptions
- 4:05Types as Values
- 4:37Generic Types
- 5:17Fill In The Code
- 5:37Type Phrasing
- 5:51Type Safety in the Type System?
- 6:37Tuple Types!
- 9:16Introducing Integers
- 10:09Zero: Using Mapped Types
- 11:08More Mapping
- 11:58Addition With Bits
- 12:46Adding 3 Bits
- 14:56Reference: JavaScript Implementation
- 16:16Int8Add: Repeat for the rest of the bits
- 17:55Tests in the Type System!?
related talks
29mBuilding an 8-Bit Adder Using Only Types
54mThe Fun Side of Advanced TypeScript: An Interactive Coding Session
42mLogic with Advanced TypeScript Types
44mA Deep Dive Into Advanced Typescript: A Live Coding Expedition
47mPattern mayhem: a binary tree in types
44mA Deep Dive Into Advanced TypeScript - A Live Coding Expedition
54mAdvanced TypeScript
01h 05mBusy TypeScript Developer’s Guide to Advanced TypeScript
