-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Changes from 2 commits
59d027b
4eaee73
fe570ba
f825b9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
tests/cases/compiler/propertyAccess3.ts(2,5): error TS2339: Property 'toBAZ' does not exist on type 'boolean'. | ||
Property 'toBAZ' does not exist on type 'true'. | ||
|
||
|
||
==== tests/cases/compiler/propertyAccess3.ts (1 errors) ==== | ||
var foo: boolean; | ||
foo.toBAZ(); | ||
~~~~~ | ||
!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'. | ||
!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'. | ||
!!! error TS2339: Property 'toBAZ' does not exist on type 'true'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks weird - let's exclude There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great minds think and read GitHub on Sunday nights alike There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow GitHub syncs weird-like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
declare const x: "foo" | "bar";
x.nope(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
tests/cases/compiler/unionPropertyExistance.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be happy to. |
||
Property 'onlyInB' does not exist on type 'A'. | ||
tests/cases/compiler/unionPropertyExistance.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'. | ||
Property 'notInC' does not exist on type 'C'. | ||
tests/cases/compiler/unionPropertyExistance.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'. | ||
Property 'notInB' does not exist on type 'B'. | ||
tests/cases/compiler/unionPropertyExistance.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'. | ||
Property 'notInB' does not exist on type 'B'. | ||
tests/cases/compiler/unionPropertyExistance.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'. | ||
Property 'inNone' does not exist on type 'A'. | ||
|
||
|
||
==== tests/cases/compiler/unionPropertyExistance.ts (5 errors) ==== | ||
interface A { | ||
inAll: string; | ||
notInB: string; | ||
notInC: string; | ||
} | ||
|
||
interface B { | ||
inAll: boolean; | ||
onlyInB: number; | ||
notInC: string; | ||
} | ||
|
||
interface C { | ||
inAll: number; | ||
notInB: string; | ||
} | ||
|
||
type AB = A | B; | ||
type ABC = C | AB; | ||
|
||
var ab: AB; | ||
var abc: ABC; | ||
|
||
ab.onlyInB; | ||
~~~~~~~ | ||
!!! error TS2339: Property 'onlyInB' does not exist on type 'AB'. | ||
!!! error TS2339: Property 'onlyInB' does not exist on type 'A'. | ||
|
||
ab.notInC; // Ok | ||
abc.notInC; | ||
~~~~~~ | ||
!!! error TS2339: Property 'notInC' does not exist on type 'ABC'. | ||
!!! error TS2339: Property 'notInC' does not exist on type 'C'. | ||
ab.notInB; | ||
~~~~~~ | ||
!!! error TS2339: Property 'notInB' does not exist on type 'AB'. | ||
!!! error TS2339: Property 'notInB' does not exist on type 'B'. | ||
abc.notInB; | ||
~~~~~~ | ||
!!! error TS2339: Property 'notInB' does not exist on type 'ABC'. | ||
!!! error TS2339: Property 'notInB' does not exist on type 'B'. | ||
|
||
abc.inAll; // Ok | ||
abc.inNone; | ||
~~~~~~ | ||
!!! error TS2339: Property 'inNone' does not exist on type 'ABC'. | ||
!!! error TS2339: Property 'inNone' does not exist on type 'A'. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//// [unionPropertyExistance.ts] | ||
interface A { | ||
inAll: string; | ||
notInB: string; | ||
notInC: string; | ||
} | ||
|
||
interface B { | ||
inAll: boolean; | ||
onlyInB: number; | ||
notInC: string; | ||
} | ||
|
||
interface C { | ||
inAll: number; | ||
notInB: string; | ||
} | ||
|
||
type AB = A | B; | ||
type ABC = C | AB; | ||
|
||
var ab: AB; | ||
var abc: ABC; | ||
|
||
ab.onlyInB; | ||
|
||
ab.notInC; // Ok | ||
abc.notInC; | ||
ab.notInB; | ||
abc.notInB; | ||
|
||
abc.inAll; // Ok | ||
abc.inNone; | ||
|
||
//// [unionPropertyExistance.js] | ||
var ab; | ||
var abc; | ||
ab.onlyInB; | ||
ab.notInC; // Ok | ||
abc.notInC; | ||
ab.notInB; | ||
abc.notInB; | ||
abc.inAll; // Ok | ||
abc.inNone; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
interface A { | ||
inAll: string; | ||
notInB: string; | ||
notInC: string; | ||
} | ||
|
||
interface B { | ||
inAll: boolean; | ||
onlyInB: number; | ||
notInC: string; | ||
} | ||
|
||
interface C { | ||
inAll: number; | ||
notInB: string; | ||
} | ||
|
||
type AB = A | B; | ||
type ABC = C | AB; | ||
|
||
var ab: AB; | ||
var abc: ABC; | ||
|
||
ab.onlyInB; | ||
|
||
ab.notInC; // Ok | ||
abc.notInC; | ||
ab.notInB; | ||
abc.notInB; | ||
|
||
abc.inAll; // Ok | ||
abc.inNone; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: Nonexistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reportNonexistentProperty