Skip to content

Commit f825b9c

Browse files
committed
Add additional tests to unionPropertyExistence
1 parent fe570ba commit f825b9c

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

tests/baselines/reference/unionPropertyExistence.errors.txt

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
tests/cases/compiler/unionPropertyExistence.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'.
1+
tests/cases/compiler/unionPropertyExistence.ts(27,3): error TS2339: Property 'nope' does not exist on type '"foo" | "bar"'.
2+
Property 'nope' does not exist on type '"foo"'.
3+
tests/cases/compiler/unionPropertyExistence.ts(28,6): error TS2339: Property 'onlyInB' does not exist on type 'B | "foo"'.
4+
Property 'onlyInB' does not exist on type '"foo"'.
5+
tests/cases/compiler/unionPropertyExistence.ts(30,6): error TS2339: Property 'length' does not exist on type 'B | "foo"'.
6+
Property 'length' does not exist on type 'B'.
7+
tests/cases/compiler/unionPropertyExistence.ts(32,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'.
28
Property 'onlyInB' does not exist on type 'A'.
3-
tests/cases/compiler/unionPropertyExistence.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'.
9+
tests/cases/compiler/unionPropertyExistence.ts(35,5): error TS2339: Property 'notInC' does not exist on type 'ABC'.
410
Property 'notInC' does not exist on type 'C'.
5-
tests/cases/compiler/unionPropertyExistence.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'.
11+
tests/cases/compiler/unionPropertyExistence.ts(36,4): error TS2339: Property 'notInB' does not exist on type 'AB'.
612
Property 'notInB' does not exist on type 'B'.
7-
tests/cases/compiler/unionPropertyExistence.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'.
13+
tests/cases/compiler/unionPropertyExistence.ts(37,5): error TS2339: Property 'notInB' does not exist on type 'ABC'.
814
Property 'notInB' does not exist on type 'B'.
9-
tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'.
15+
tests/cases/compiler/unionPropertyExistence.ts(40,5): error TS2339: Property 'inNone' does not exist on type 'ABC'.
1016
Property 'inNone' does not exist on type 'A'.
1117

1218

13-
==== tests/cases/compiler/unionPropertyExistence.ts (5 errors) ====
19+
==== tests/cases/compiler/unionPropertyExistence.ts (8 errors) ====
1420
interface A {
1521
inAll: string;
1622
notInB: string;
@@ -34,6 +40,23 @@ tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'in
3440
var ab: AB;
3541
var abc: ABC;
3642

43+
declare const x: "foo" | "bar";
44+
declare const bFoo: B | "foo";
45+
46+
x.nope();
47+
~~~~
48+
!!! error TS2339: Property 'nope' does not exist on type '"foo" | "bar"'.
49+
!!! error TS2339: Property 'nope' does not exist on type '"foo"'.
50+
bFoo.onlyInB;
51+
~~~~~~~
52+
!!! error TS2339: Property 'onlyInB' does not exist on type 'B | "foo"'.
53+
!!! error TS2339: Property 'onlyInB' does not exist on type '"foo"'.
54+
x.length; // Ok
55+
bFoo.length;
56+
~~~~~~
57+
!!! error TS2339: Property 'length' does not exist on type 'B | "foo"'.
58+
!!! error TS2339: Property 'length' does not exist on type 'B'.
59+
3760
ab.onlyInB;
3861
~~~~~~~
3962
!!! error TS2339: Property 'onlyInB' does not exist on type 'AB'.
@@ -57,4 +80,5 @@ tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'in
5780
abc.inNone;
5881
~~~~~~
5982
!!! error TS2339: Property 'inNone' does not exist on type 'ABC'.
60-
!!! error TS2339: Property 'inNone' does not exist on type 'A'.
83+
!!! error TS2339: Property 'inNone' does not exist on type 'A'.
84+

tests/baselines/reference/unionPropertyExistence.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ type ABC = C | AB;
2222
var ab: AB;
2323
var abc: ABC;
2424

25+
declare const x: "foo" | "bar";
26+
declare const bFoo: B | "foo";
27+
28+
x.nope();
29+
bFoo.onlyInB;
30+
x.length; // Ok
31+
bFoo.length;
32+
2533
ab.onlyInB;
2634

2735
ab.notInC; // Ok
@@ -30,11 +38,16 @@ ab.notInB;
3038
abc.notInB;
3139

3240
abc.inAll; // Ok
33-
abc.inNone;
41+
abc.inNone;
42+
3443

3544
//// [unionPropertyExistence.js]
3645
var ab;
3746
var abc;
47+
x.nope();
48+
bFoo.onlyInB;
49+
x.length; // Ok
50+
bFoo.length;
3851
ab.onlyInB;
3952
ab.notInC; // Ok
4053
abc.notInC;

tests/cases/compiler/unionPropertyExistence.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ type ABC = C | AB;
2121
var ab: AB;
2222
var abc: ABC;
2323

24+
declare const x: "foo" | "bar";
25+
declare const bFoo: B | "foo";
26+
27+
x.nope();
28+
bFoo.onlyInB;
29+
x.length; // Ok
30+
bFoo.length;
31+
2432
ab.onlyInB;
2533

2634
ab.notInC; // Ok
@@ -29,4 +37,4 @@ ab.notInB;
2937
abc.notInB;
3038

3139
abc.inAll; // Ok
32-
abc.inNone;
40+
abc.inNone;

0 commit comments

Comments
 (0)