Typescript

Type Guard Composition

Building composable type guard systems in TypeScript where runtime validation seamlessly integrates with compile-time type narrowing. Type guards like isString(x): x is string enable safe runtime checks, but composing them requires careful design. This explores combinators for union guards or(isNumber, isString): x is number | string, intersection guards and(hasName, hasAge): x is Person, and variadic patterns that preserve type inference. The result: elegant runtime validation that TypeScript’s control flow fully understands.

Unchained Tuple Types

Using TypeScript’s asserts syntax to create imperative-style type mutations, moving beyond method chaining to more familiar iterative patterns for complex type operations.

Chained Tuple Types

TypeScript 4.1’s variadic tuple types enable building complex type-safe data structures through method chaining, where each operation expands the chain’s type signature at compile time.

Self Modifying Type Predicates in Typescript

TypeScript’s type predicates can modify the type of this itself, enabling self-modifying type behavior that approaches dependent types. By implementing is<K extends keyof ShapeTypes>(type: K): this is ShapeTypes[K] on abstract classes, we achieve compile-time type narrowing where shape.is('circle') transforms the shape variable’s type from Shape to Circle, unlocking properties like shape.radius within conditional blocks.

Dijkstra's Shunting Yard in Typescript

A functional TypeScript implementation of Dijkstra’s classic algorithm for parsing mathematical expressions, converting infix notation to reverse Polish notation for stack-based evaluation.