Making Referential Stability a Type
Summary
This article proposes encoding referential stability as a branded type in TypeScript to enforce stable references in React. It introduces a Stable<T> contract and demonstrates how a dedicated stableref entry can enforce stability at the type level, including usage in contexts, hooks, and memoization. It also discusses the difference between runtime memoization and compile-time guarantees, and when to apply module augmentation versus a specialized import.