-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
array intersection [] & distributive law
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Type System Behaviour.
β― Playground Link
π» Code
type ArrayOfIntersection = Array<{ x: number } & { y: string }>;
type IntersectionOfArrays = Array<{ x: number }> & Array<{ y: string }>;
let aoi: ArrayOfIntersection;
let ioa: IntersectionOfArrays;
function test() {
ioa = aoi;
aoi = ioa; // Type error
}
π Actual behavior
The aoi = ioa
assignement has a type error, while Array<A & B>
should be exactly equal to Array<A> & Array<B>
:
- Values in an
Array<A & B>
have typeA & B
. - Values in an
Array<A> & Array<B>
have type A and also have type B -- that is: they have typeA & B
.
So these two types are equivalent, yet Typescript accepts assignment in one direction but not the other.
π Expected behavior
The above code should compile without error.
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created