You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Make & intersection actually mean intersection of properties
This means the following code should be an error because we cannot intersect string and int32(what we do if you intersect explicitly)
alias MergedBad = Record<int32> & {name: string};
^ cannot intersect record ...
2. Allow spreading Record<T>
This would make & and ... meaning diverge:
& would mean intersection of types(as described above) and so would merge the properties and if types are not able to be merged it would be an error/resolve to never
... would mean spread the properties and so would add extra properties. This means if you spread extra properties then those get added, if properties name conflict then it is an error. If you spread a Record, it describe the remaining properties.
model WithSpread {
name: string;
age: int32;
...Record<string>;
}
The code above would mean you have a model with a property name of type string, a property age of type int32 and any other property of type string.
Multiple ...Record<T>
As ... allows multiple instance in the same model it is possible to have multiple ...Record<T> in the same model. This would mean that each ...Record<T> would be a union of each other.
If you spread Record<string> and Record<int32> it means all extra properties could either be a string or int32. You are basically saying I am spreading some string properties and some int32 properties.
model WithSpread {
name: string;
enabled: boolean;
...Record<string>;
...Record<itn32>;
}
// is equivalent to
model WithSpread {
name: string;
enabled: boolean;
...Record<int32 | string>;
}
Difference with is Record<T>(or extends Record<T>)
model Foo is Record<T> will be defining the indexer for Foo which means all properties added to Foo must be of type T. This also means that Foo can be used when a constraints of type Record<T> is needed.
However when spreading Record<T> it will not be setting the indexer as some properties could technically be of a different type.
model Template<T extends Record<string>> {t: T}
model WithSpread {
age: int32;
...Record<string>;
}
model WithIs is Record<string> {
string: string;
}
model Test {
good: Template<Record<string>>;
goodWithIs: Template<WithIs>;
bad: Template<WithSpread>;
^ error WithSpread is not assignable to Record<string>
}
Technically having this would also pass the constraint above as all the extra properties are also assignable to the constraint.
```tsp
model WithSpread {
name: string;
...Record<string>;
}
is or extends a model with ...Record<T>
At this point it should be an error if you try to define a property that is incompatible with the base model spread indexer.
Other items
Add docs
The text was updated successfully, but these errors were encountered:
Implementation for design #2442
1. Make
&
intersection actually mean intersection of propertiesThis means the following code should be an error because we cannot intersect
string
andint32
(what we do if you intersect explicitly)2. Allow spreading
Record<T>
This would make
&
and...
meaning diverge:&
would mean intersection of types(as described above) and so would merge the properties and if types are not able to be merged it would be an error/resolve tonever
...
would mean spread the properties and so would add extra properties. This means if you spread extra properties then those get added, if properties name conflict then it is an error. If you spread a Record, it describe the remaining properties.The code above would mean you have a model with a property
name
of typestring
, a propertyage
of typeint32
and any other property of typestring
.Multiple
...Record<T>
As
...
allows multiple instance in the same model it is possible to have multiple...Record<T>
in the same model. This would mean that each...Record<T>
would be a union of each other.If you spread
Record<string>
andRecord<int32>
it means all extra properties could either be astring
orint32
. You are basically saying I am spreading some string properties and some int32 properties.Difference with
is Record<T>
(orextends Record<T>
)model Foo is Record<T>
will be defining the indexer forFoo
which means all properties added toFoo
must be of typeT
. This also means thatFoo
can be used when a constraints of typeRecord<T>
is needed.However when spreading
Record<T>
it will not be setting the indexer as some properties could technically be of a different type.Technically having this would also pass the constraint above as all the extra properties are also assignable to the constraint.
is
orextends
a model with...
Record<T>
At this point it should be an error if you try to define a property that is incompatible with the base model spread indexer.
Other items
The text was updated successfully, but these errors were encountered: