liveBook · Manning

Type compatibility

As explained in Building User-Friendly DSLs

A relation between types specifying whether values of one type can be used where values of another type are expected.

Type compatibility determines whether a value of one type may be used where another type is expected. A simple type system can define compatibility as equality: two type objects match when their IDs match. Practical systems often use directional assignability instead, where type T is assignable to type U without requiring the reverse. section 13.3

Implementation uses compatibility to:

  • Compare type objects by stable IDs rather than JavaScript object identity. section 13.3

How Building User-Friendly DSLs covers it

How deep it goes
Implements equality-based matching and contrasts it with assignability, inheritance, and coercion without implementing those broader relations.
Examples
Demonstrates compatibility with amount, date range, percentage, untyped values, binary subtraction, attribute assignments, and display markers.
What you can do after
Build it from scratch by representing types as objects, comparing stable IDs, and propagating checks into constraints and projections.
How it connects
Connects type equality with assignability, subtyping, inheritance, generalization, type coercion, constraints, and operator type checking.

Also explained in

Compare how 3 books explain type compatibility →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.