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

Type should be simplified for quickInfo #16404

Closed
ghost opened this issue Jun 9, 2017 · 5 comments
Closed

Type should be simplified for quickInfo #16404

ghost opened this issue Jun 9, 2017 · 5 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@ghost
Copy link

ghost commented Jun 9, 2017

TypeScript Version: nightly (2.4.0-dev.20170609)

Code

/// <reference path="fourslash.ts" />
////interface I { x: string | number; }
////declare const i: I & { x: number };
////i./**/x;

verify.quickInfoAt("", "(property) x: number");

Expected behavior:

Test succeeds.

Actual behavior:

Shows (property) x: number | (string & number).

@mhegazy
Copy link
Contributor

mhegazy commented Jun 9, 2017

not sure what you mean by "simplified". that s the type of x.

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Jun 9, 2017
@ghost
Copy link
Author

ghost commented Jun 9, 2017

When we intersect { x: number } with { x: string | number }, can't we simplify it to just { x: number }?

@mhegazy
Copy link
Contributor

mhegazy commented Jun 9, 2017

nope... it is not just a number, it is number & (string | number) which then distributes to (number & string) | (number & number) which is (number & string) | number.

it is true that number & string is an empty set, but we have no special treatment for these in intersection type.
you could argue that the compiler should reduce types that are guaranteed to have no values to never, but that would break cases like tagged types (e.g. string & {tag: any}). we do use that for instance see Path in src\compiler\types.ts

@jcalz
Copy link
Contributor

jcalz commented Jun 9, 2017

@mhegazy Even if (number & string) weren't empty, number & (string | number) should still reduce to number by absorption (see coincidentally recent #16386).

@mhegazy
Copy link
Contributor

mhegazy commented Aug 17, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Aug 17, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants