Show an elaboration when accessing a non-existent property of a union type#10582
Conversation
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.
|
Hi @oijazsh, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! 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 |
There was a problem hiding this comment.
This looks weird - let's exclude TypeFlags.Boolean along with TypeFlags.Enum on line 10814
There was a problem hiding this comment.
Eugh.
How about for enums and booleans we don't dive in? Specifically, you can check TypeFlags.Boolean and TypeFlags.Enum.
There was a problem hiding this comment.
Great minds think and read GitHub on Sunday nights alike
There was a problem hiding this comment.
Actually, TypeFlags.Primitive is probably fine to check too.
There was a problem hiding this comment.
Wow GitHub syncs weird-like
There was a problem hiding this comment.
Primitive is probably correct. Let's have a test for
declare const x: "foo" | "bar";
x.nope();|
Looks pretty good to me after a couple minor fixes. @mhegazy thoughts on letting this into |
|
Fixed the typo and excluded unions that are also |
|
sorry for the delay. loos good. |
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:
(It probably should in the second case, but that hasn't been discussed)