Type equality asserts that two type expressions denote the same type. When types are represented as objects, compare their stable IDs rather than JavaScript object identity. section 13.3
An implementation can use type equality to:
- Define areEqual(actual, expected) as actual.id === expected.id. section 13.3
- Check operator rules, such as requiring the right operand of “of” to equal the built-in amount type. section 13.3
- Validate that an attribute’s declared type equals the type inferred for its value, then report both rendered types when they differ. section 13.3
- Select presentation details such as dollar, days, or percent markers by comparing a value’s type with built-in types. section 13.3
Comparing an attribute and its value
If an attribute declares amount but its value infers as percentage, areEqual returns false. Constraint checking can then report that the attribute and value types must match, rendering the two types for the diagnostic. section 13.3
Table 13.1 The type objects for built-in types
|
Type name
|
ID
|
Concept label
|
Settings
|
|---|---|---|---|
amount
|
numberType_amount
|
Number Type
|
{ "unit": "$" }
|
date range
|
numberType_dateRange
|
Interval Type
|
{ "unit": "day" }
|
percentage
|
numberType_percentage
|
Number Type
|
{ "unit": "%" }
|
untype
|
untype_untype
|
Untype
|
{}
|
Built-in type objects make equality concrete: amount, date range, percentage, and untype each have distinct IDs, concepts, and settings. section 13.3
This equality-based notion of matching is deliberately simple. Type compatibility can instead use directional assignability, including relationships involving inheritance or type coercion. MPS can produce type equalities for algorithmic inference. section 13.3 section 15.4.2
