Skip to content

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

Merged
mhegazy merged 4 commits into
microsoft:masterfrom
ojsheikh:TS2339
Sep 13, 2016
Merged

Show an elaboration when accessing a non-existent property of a union type#10582
mhegazy merged 4 commits into
microsoft:masterfrom
ojsheikh:TS2339

Conversation

@ojsheikh

Copy link
Copy Markdown
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
Copy Markdown

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'. No newline at end of file
!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'.
!!! error TS2339: Property 'toBAZ' does not exist on type 'true'. No newline at end of file

@RyanCavanaugh RyanCavanaugh Aug 29, 2016

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Fixed the typo and excluded unions that are also Primitive.

@mhegazy

mhegazy commented Sep 13, 2016

Copy link
Copy Markdown
Contributor

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