-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapped types break for-in
loops with intersections
#13023
Comments
This is working as intended, the fact that it was previously allowed was a bug. A type A = {
a: string;
x: { s: string };
}
type B = {
b: string;
x: { t: string };
} The intersection type AB = {
a: string;
b: string;
x: { s: string, t: string };
} Neither property |
I agree that in a deep setting the new behaviour is the correct one, however it is also a breaking change introduced in version 2.1 and should be marked as such. |
PS: shallow intersections seem to be more natural. Will they ever be supported? Is the deep behaviour actually used in RWC? |
The What's new documentation on intersection types features the very same |
@gcnew If you want "shallow intersections" following the logic of |
@weswigham Thank you! The major problem I'm after is that basically all the information and marketing of intersection types are incomplete at best (leaning to wrong). This has created a flawed mental model for many of us. The unfortunate state we are currently in should be very explicitly explained and fixed in the new documentation (even if the behaviour is changed to match the status-quo explanation). Also the TypeScript book and What's new should be retroactively updated. I believe the revelation @ahejlsberg made is world breaking not only for me. |
The original PR on intersection types, #3622, has all of the semantics described in a fair amount of detail. |
@ahejlsberg Yes, #3622 has the semantics described, however they are:
The My proposal is to state the intended semantics clearly and add an appropriate notice on the pertinent resources. Otherwise people reading the official resources will still be led astray. |
I'm not sure I understand the notion of shallow intersections. |
It seems Flow has taken the shallow path with the left operand being a base type and the right one an extension. link It is also what I had inferred form the TS documentation as nothing is said about intersections being deep and all the motivating examples being shallow. The inclusion of From another perspective this is breaking the code in the official documentation. There are two routes of action, either the behaviour is changed to match the documentation, or the documentation is updated. In both cases there should be a notice clearing up the confusion and all the relevant parts updated. |
TypeScript Version: nightly
The following used to work but is broken now.
Code
The text was updated successfully, but these errors were encountered: