Capture Semantics
As part of my efforts on ts-unify, I needed a way to represent ‘capturing’ and transforming values in a data structure from one form to another. This article elucidates those extraction semantics.
As part of my efforts on ts-unify, I needed a way to represent ‘capturing’ and transforming values in a data structure from one form to another. This article elucidates those extraction semantics.
I’ve been playing with codemod transformations for TypeScript using
jscodeshift
(from Facebook) and
ts-pattern
. Working closely with
these has made me want a declarative type-aware codemod engine for TypeScript,
which I haven’t yet been able to find.
This interactive tool demonstrates a steganographic technique using Unicode variation selectors (U+E0100
-U+E017F
) to encode hidden text within visible strings. By mapping ASCII characters to these invisible codepoints, messages can be embedded undetected - a potential vector for prompt injection attacks whereby LLMs may process hidden instructions.
The hkt-toolbelt
library introduces kind reification - transforming abstract type-level functions into concrete runtime signatures. This enables point-free programming where compositions like Pipe<[Map<Inc>, Filter<IsEven>, Reduce<Add>]>
become executable functions with 1:1 corresponding types. By bridging TypeScript’s type system with runtime code, we can write type-level pipelines that are both type-safe and actually invokable.
to reify: make (something abstract) more concrete or real.
Implementing the famous Collatz conjecture entirely within TypeScript’s type system, demonstrating type-level arithmetic and recursive computation. The sequence follows $n \rightarrow n/2$ if even, $n \rightarrow 3n+1$ if odd, conjecturing all positive integers reach 1. Using template literal types and conditional type recursion, we can compute Collatz<27>
yielding the 111-step sequence purely at compile time - pushing TypeScript’s type system to perform actual mathematical computation.
This deep dive explores implementing mathematically-correct function composition with full type safety. We’ll build a compose
function where compose<A, B, C>(f: B→C, g: A→B): A→C
validates type compatibility at compile time, handle variadic arguments through recursive types, and ensure composed pipelines like compose(toString, Math.sqrt, parseInt)
automatically infer as (s: string) => string
while preventing invalid compositions from compiling.
Designing a type-safe plugin system in TypeScript that maintains strong typing guarantees while allowing extensible functionality. Using discriminated unions and generic constraints, we can build plugin architectures where registerPlugin<T extends Plugin>()
enforces interface contracts at compile time. This approach enables dynamic feature extension while preserving full IDE support and preventing runtime type errors - useful for maintaining large-scale extensible applications.
A performance-optimized, non-recursive implementation of a type-level array inclusion operator in TypeScript. By leveraging tuple spread syntax and conditional types instead of recursive patterns, we achieve Includes<[1, 2, 3], 2>
evaluation in O(1) type instantiation depth rather than O(n). This technique improves compile-time performance for large tuple operations, avoiding TypeScript’s recursion depth limits while maintaining the same type-level guarantees.
Implementing point-free (tacit) programming patterns in TypeScript using Higher Kinded Types to overcome traditional type system limitations. Point-free style eliminates explicit arguments, composing functions like pipe(map(inc), filter(isEven), reduce(add))
instead of x => x.map(inc).filter(isEven).reduce(add)
. Through HKT encodings, we achieve true tacit programming where type inference flows through the entire pipeline, enabling cleaner functional abstractions without sacrificing TypeScript’s type safety.
Extending Higher Kinded Types with variadic composition patterns, enabling clean functional composition while preserving complete type information. Building on HKT foundations, this explores variadic compositions where Compose<[F, G, H, ...]>
handles arbitrary function chains with full type inference. Using advanced tuple manipulation and distributive conditional types, we achieve compositions like pipe(map, flatten, filter, reduce)
that maintain type safety across any number of transformations - a significant advancement in TypeScript’s functional programming capabilities.