A design exploration for user-defined value types in JavaScript, written by a TC39 contributor. It argues that JavaScript's primitive/object divide is too rigid and proposes 'value objects' — typed objects that are immutable and compared by field equality rather than identity. The post covers the problems with using plain objects for value-like data (aliasing, mutation, optimization barriers), explains why modeling user-defined value types on primitives doesn't scale, and proposes building on typed objects via a `.valueType()` transformer. Concrete examples show how struct and array value types would behave, including copy-out semantics and redefined `===` equality. Integration with ES6 Map and Set is also discussed.
Table of contents
The need for extensible value typesValue types are just both tasty and nutritiousPrimitive types do not generalize to user-defined value typesGeneralizing typed objects to support user-defined value typesExplanation through examplesFrozen arraysA side note: Integration with Map and SetAppendices2 Impressions