Skip to content
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

Better display representation for intersection types #7705

Open
louy opened this issue Mar 27, 2016 · 7 comments
Open

Better display representation for intersection types #7705

louy opened this issue Mar 27, 2016 · 7 comments
Labels
Effort: Difficult Good luck. Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@louy
Copy link

louy commented Mar 27, 2016

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

type T1 = {};
type T2 = {test: number};
type J = T1 & T2;

Expected behavior:

var x: J;
typeof x; // {test: number}

Actual behavior:

var x: J;
typeof x; // {} & {test: number}
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Mar 28, 2016
@DanielRosenwasser DanielRosenwasser changed the title Better join types display Better intersection display for intersection types Apr 6, 2016
@DanielRosenwasser DanielRosenwasser changed the title Better intersection display for intersection types Better display representation for intersection types Apr 6, 2016
@JabX
Copy link

JabX commented Apr 13, 2016

👍
I use intersections a lot and I would love to have this feature.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 13, 2016

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 }

@louy
Copy link
Author

louy commented Apr 13, 2016

The second actually.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 13, 2016

ok 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 }

@JabX
Copy link

JabX commented Apr 14, 2016

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.

@zpdDG4gta8XKpMCd
Copy link

related #6070

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Effort: Difficult Good luck. and removed In Discussion Not yet reached consensus labels May 9, 2016
@RyanCavanaugh RyanCavanaugh added this to the Community milestone May 9, 2016
@RyanCavanaugh
Copy link
Member

Accepting 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Effort: Difficult Good luck. Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants