Type Relations
Type hierarchy
Model with properties
When determining if type S
can be assigned to type T
, if T
is a model with properties, it checks whether all those properties are present in S
and if their types can be assigned to the type of the corresponding property in T
.
For instance,
Record<T>
A record is a model indexed with a string with a value of T. It represents a model where all properties (string keys) are assignable to the type T. You can assign a model expression where all the properties are of type T or another model that is
also a Record<T>
.
Why isnโt the last case assignable to Record<int32>
?
In this scenario,
The reason why model S
is not assignable, but the model expression { foo: 123; bar: 456; }
is, is because model S could be extended with additional properties that might not be compatible.
For instance, if you add a new model,
Here, Foo
is assignable to S
following the model with property logic, and if S
was assignable to Record<int32>
, Foo
would also be passable. However, this is now invalid as otherProp
is not an int32
property.