Repository navigation
Better display representation for intersection types #7705
Description
Activity
- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensus
on Mar 28, 2016 - changed the title
[-]Better join types display[/-][+]Better intersection display for intersection types[/+]on Apr 6, 2016 - changed the title
[-]Better intersection display for intersection types[/-][+]Better display representation for intersection types[/+]on Apr 6, 2016 👍
I use intersections a lot and I would love to have this feature.so just to be clear is the request 1. to remove the empty object type if exists, or 2. to collapse all types. i.e.:
type T = { } & { a: number } & { b: string }; var x: T; // What is x? // 1. { a: number } & { b: string } // 2. { a: number, b: string }
The second actually.
Reacted by Damien Frikhaok one more clarification, i assume this only applies to anonymous types. so 2.a would be the desired behavior.
class C { c: boolean; } type T = C & { a: number } & { b: string }; var x: T; // What is x? // 2.a C & { a: number; b: string } // 2.b { a: number, b: string; c: boolean }
I suppose it's better to limit this to anonymous types, or else it could rapidly go out of control with "big" named types, and you'll lose some type information.
related #6070
- addedHelp WantedYou can do thisYou can do thisEffort: DifficultGood luck.Good luck.and removedIn DiscussionNot yet reached consensusNot yet reached consensus
on May 9, 2016 - added this to the This milestone has been deleted milestone
on May 9, 2016 RyanCavanaugh commented
on May 9, 2016 MemberMore actionsAccepting PRs, with a big caveat. This is actually quite a bit trickier than it appears because of how the compiler handles anonymous self-referential types. A PR here should be accompanied by a large test suite of recursively self-referential types to ensure there aren't any lingering runaway recursion bugs.
See also comments in #8228.
I'm not sure if this has been discussed before, but join types are mostly unreadable. I think the type should be prettified somehow before being displayed to the user.
TypeScript Version:
1.8
Code
Expected behavior:
Actual behavior: