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

Show an elaboration when accessing a non-existent property of a union type #10582

Merged
merged 4 commits into from
Sep 13, 2016

Conversation

ojsheikh
Copy link
Contributor

This fixes issue #10256 by showing an elaboration when accessing a non-existant property of a union type. It does not show an elaboration in the following cases:

  • If the union is a enum
  • If all the subtypes of the union do indeed contain the property but at least one of them has the property declared under a stricter context than the current one

(It probably should in the second case, but that hasn't been discussed)

Fixes microsoft#10256. Accessing a non-existant property on union types should
now show an elaboration in the error message specifying the first
constituent type that lacks the property.
@msftclas
Copy link

Hi @oijazsh, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, MSBOT;

!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'.
!!! error TS2339: Property 'toBAZ' does not exist on type 'true'.
Copy link
Member

@RyanCavanaugh RyanCavanaugh Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks weird - let's exclude TypeFlags.Boolean along with TypeFlags.Enum on line 10814

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eugh.

How about for enums and booleans we don't dive in? Specifically, you can check TypeFlags.Boolean and TypeFlags.Enum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great minds think and read GitHub on Sunday nights alike

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, TypeFlags.Primitive is probably fine to check too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow GitHub syncs weird-like

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primitive is probably correct. Let's have a test for

declare const x: "foo" | "bar";
x.nope();

@RyanCavanaugh
Copy link
Member

Looks pretty good to me after a couple minor fixes. @mhegazy thoughts on letting this into master vs the 2.1 branch?

@ojsheikh ojsheikh changed the title Ts2339 Show an elaboration when accessing a non-existent property of a union type Aug 29, 2016
@ojsheikh
Copy link
Contributor Author

Fixed the typo and excluded unions that are also Primitive.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 13, 2016

sorry for the delay. loos good.

@mhegazy mhegazy merged commit a612d58 into microsoft:master Sep 13, 2016
@ojsheikh ojsheikh deleted the TS2339 branch September 14, 2016 02:34
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants