Skip to content

Commit 855fd84

Browse files
committed
Baseline updates
1 parent e81d845 commit 855fd84

20 files changed

+651
-71
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//// [consistentUnionSubtypeReduction.ts]
2+
// https://github.com/microsoft/TypeScript/issues/31155
3+
4+
declare const MyArray: {
5+
isArray<T>(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[];
6+
};
7+
8+
declare const a: readonly string[] | string;
9+
declare const b: string[] | string;
10+
declare const c: unknown;
11+
12+
if (MyArray.isArray(a)) {
13+
a; // readonly string[]
14+
}
15+
else {
16+
a; // string
17+
}
18+
a; // readonly string[] | string;
19+
20+
if (MyArray.isArray(b)) {
21+
b; // string[] | string;
22+
}
23+
else {
24+
b; // string
25+
}
26+
b; // string[] | string;
27+
28+
if (MyArray.isArray(c)) {
29+
c; // any[]
30+
}
31+
32+
33+
function f<T>(x: T) {
34+
const a: readonly T[] | string = null!;
35+
const b: T[] | string = null!;
36+
const c: T = null!;
37+
38+
if (MyArray.isArray(a)) {
39+
a; // readonly T[]
40+
}
41+
else {
42+
a; // string
43+
}
44+
a; // readonly T[] | string;
45+
46+
if (MyArray.isArray(b)) {
47+
b; // T[]
48+
}
49+
else {
50+
b; // string
51+
}
52+
b;
53+
54+
if (MyArray.isArray(c)) {
55+
c; // T & (T extends readonly any[] ? readonly any[] : any[])
56+
}
57+
}
58+
59+
60+
//// [consistentUnionSubtypeReduction.js]
61+
// https://github.com/microsoft/TypeScript/issues/31155
62+
if (MyArray.isArray(a)) {
63+
a; // readonly string[]
64+
}
65+
else {
66+
a; // string
67+
}
68+
a; // readonly string[] | string;
69+
if (MyArray.isArray(b)) {
70+
b; // string[] | string;
71+
}
72+
else {
73+
b; // string
74+
}
75+
b; // string[] | string;
76+
if (MyArray.isArray(c)) {
77+
c; // any[]
78+
}
79+
function f(x) {
80+
var a = null;
81+
var b = null;
82+
var c = null;
83+
if (MyArray.isArray(a)) {
84+
a; // readonly T[]
85+
}
86+
else {
87+
a; // string
88+
}
89+
a; // readonly T[] | string;
90+
if (MyArray.isArray(b)) {
91+
b; // T[]
92+
}
93+
else {
94+
b; // string
95+
}
96+
b;
97+
if (MyArray.isArray(c)) {
98+
c; // T & (T extends readonly any[] ? readonly any[] : any[])
99+
}
100+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
=== tests/cases/compiler/consistentUnionSubtypeReduction.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/31155
3+
4+
declare const MyArray: {
5+
>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13))
6+
7+
isArray<T>(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[];
8+
>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
9+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 3, 12))
10+
>arg : Symbol(arg, Decl(consistentUnionSubtypeReduction.ts, 3, 15))
11+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 3, 12))
12+
>arg : Symbol(arg, Decl(consistentUnionSubtypeReduction.ts, 3, 15))
13+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 3, 12))
14+
15+
};
16+
17+
declare const a: readonly string[] | string;
18+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13))
19+
20+
declare const b: string[] | string;
21+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13))
22+
23+
declare const c: unknown;
24+
>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 8, 13))
25+
26+
if (MyArray.isArray(a)) {
27+
>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
28+
>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13))
29+
>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
30+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13))
31+
32+
a; // readonly string[]
33+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13))
34+
}
35+
else {
36+
a; // string
37+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13))
38+
}
39+
a; // readonly string[] | string;
40+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 6, 13))
41+
42+
if (MyArray.isArray(b)) {
43+
>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
44+
>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13))
45+
>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
46+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13))
47+
48+
b; // string[] | string;
49+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13))
50+
}
51+
else {
52+
b; // string
53+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13))
54+
}
55+
b; // string[] | string;
56+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 7, 13))
57+
58+
if (MyArray.isArray(c)) {
59+
>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
60+
>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13))
61+
>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
62+
>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 8, 13))
63+
64+
c; // any[]
65+
>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 8, 13))
66+
}
67+
68+
69+
function f<T>(x: T) {
70+
>f : Symbol(f, Decl(consistentUnionSubtypeReduction.ts, 28, 1))
71+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11))
72+
>x : Symbol(x, Decl(consistentUnionSubtypeReduction.ts, 31, 14))
73+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11))
74+
75+
const a: readonly T[] | string = null!;
76+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9))
77+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11))
78+
79+
const b: T[] | string = null!;
80+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9))
81+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11))
82+
83+
const c: T = null!;
84+
>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 34, 9))
85+
>T : Symbol(T, Decl(consistentUnionSubtypeReduction.ts, 31, 11))
86+
87+
if (MyArray.isArray(a)) {
88+
>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
89+
>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13))
90+
>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
91+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9))
92+
93+
a; // readonly T[]
94+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9))
95+
}
96+
else {
97+
a; // string
98+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9))
99+
}
100+
a; // readonly T[] | string;
101+
>a : Symbol(a, Decl(consistentUnionSubtypeReduction.ts, 32, 9))
102+
103+
if (MyArray.isArray(b)) {
104+
>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
105+
>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13))
106+
>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
107+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9))
108+
109+
b; // T[]
110+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9))
111+
}
112+
else {
113+
b; // string
114+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9))
115+
}
116+
b;
117+
>b : Symbol(b, Decl(consistentUnionSubtypeReduction.ts, 33, 9))
118+
119+
if (MyArray.isArray(c)) {
120+
>MyArray.isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
121+
>MyArray : Symbol(MyArray, Decl(consistentUnionSubtypeReduction.ts, 2, 13))
122+
>isArray : Symbol(isArray, Decl(consistentUnionSubtypeReduction.ts, 2, 24))
123+
>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 34, 9))
124+
125+
c; // T & (T extends readonly any[] ? readonly any[] : any[])
126+
>c : Symbol(c, Decl(consistentUnionSubtypeReduction.ts, 34, 9))
127+
}
128+
}
129+
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
=== tests/cases/compiler/consistentUnionSubtypeReduction.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/31155
3+
4+
declare const MyArray: {
5+
>MyArray : { isArray<T>(arg: {} | T): arg is T extends readonly any[] ? readonly any[] : any[]; }
6+
7+
isArray<T>(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[];
8+
>isArray : <T>(arg: T | {}) => arg is T extends readonly any[] ? readonly any[] : any[]
9+
>arg : {} | T
10+
11+
};
12+
13+
declare const a: readonly string[] | string;
14+
>a : string | readonly string[]
15+
16+
declare const b: string[] | string;
17+
>b : string | string[]
18+
19+
declare const c: unknown;
20+
>c : unknown
21+
22+
if (MyArray.isArray(a)) {
23+
>MyArray.isArray(a) : boolean
24+
>MyArray.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
25+
>MyArray : { isArray<T>(arg: {} | T): arg is T extends readonly any[] ? readonly any[] : any[]; }
26+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
27+
>a : string | readonly string[]
28+
29+
a; // readonly string[]
30+
>a : readonly string[]
31+
}
32+
else {
33+
a; // string
34+
>a : string
35+
}
36+
a; // readonly string[] | string;
37+
>a : string | readonly string[]
38+
39+
if (MyArray.isArray(b)) {
40+
>MyArray.isArray(b) : boolean
41+
>MyArray.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
42+
>MyArray : { isArray<T>(arg: {} | T): arg is T extends readonly any[] ? readonly any[] : any[]; }
43+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
44+
>b : string | string[]
45+
46+
b; // string[] | string;
47+
>b : string[]
48+
}
49+
else {
50+
b; // string
51+
>b : string
52+
}
53+
b; // string[] | string;
54+
>b : string | string[]
55+
56+
if (MyArray.isArray(c)) {
57+
>MyArray.isArray(c) : boolean
58+
>MyArray.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
59+
>MyArray : { isArray<T>(arg: {} | T): arg is T extends readonly any[] ? readonly any[] : any[]; }
60+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
61+
>c : unknown
62+
63+
c; // any[]
64+
>c : any[]
65+
}
66+
67+
68+
function f<T>(x: T) {
69+
>f : <T>(x: T) => void
70+
>x : T
71+
72+
const a: readonly T[] | string = null!;
73+
>a : string | readonly T[]
74+
>null! : null
75+
>null : null
76+
77+
const b: T[] | string = null!;
78+
>b : string | T[]
79+
>null! : null
80+
>null : null
81+
82+
const c: T = null!;
83+
>c : T
84+
>null! : null
85+
>null : null
86+
87+
if (MyArray.isArray(a)) {
88+
>MyArray.isArray(a) : boolean
89+
>MyArray.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
90+
>MyArray : { isArray<T>(arg: {} | T): arg is T extends readonly any[] ? readonly any[] : any[]; }
91+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
92+
>a : string | readonly T[]
93+
94+
a; // readonly T[]
95+
>a : readonly T[]
96+
}
97+
else {
98+
a; // string
99+
>a : string
100+
}
101+
a; // readonly T[] | string;
102+
>a : string | readonly T[]
103+
104+
if (MyArray.isArray(b)) {
105+
>MyArray.isArray(b) : boolean
106+
>MyArray.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
107+
>MyArray : { isArray<T>(arg: {} | T): arg is T extends readonly any[] ? readonly any[] : any[]; }
108+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
109+
>b : string | T[]
110+
111+
b; // T[]
112+
>b : T[]
113+
}
114+
else {
115+
b; // string
116+
>b : string
117+
}
118+
b;
119+
>b : string | T[]
120+
121+
if (MyArray.isArray(c)) {
122+
>MyArray.isArray(c) : boolean
123+
>MyArray.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
124+
>MyArray : { isArray<T>(arg: {} | T): arg is T extends readonly any[] ? readonly any[] : any[]; }
125+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
126+
>c : T
127+
128+
c; // T & (T extends readonly any[] ? readonly any[] : any[])
129+
>c : T & (T extends readonly any[] ? readonly any[] : any[])
130+
}
131+
}
132+

tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export const updateIfChanged = <T>(t: T) => {
6767
>assign : { <T, U>(target: T, source: U): T & U; <T, U, V>(target: T, source1: U, source2: V): T & U & V; <T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
6868
>Array.isArray(u) ? [] : {} : undefined[] | {}
6969
>Array.isArray(u) : boolean
70-
>Array.isArray : (arg: any) => arg is any[]
70+
>Array.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
7171
>Array : ArrayConstructor
72-
>isArray : (arg: any) => arg is any[]
72+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
7373
>u : U
7474
>[] : undefined[]
7575
>{} : {}

tests/baselines/reference/fixSignatureCaching.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,9 +1109,9 @@ define(function () {
11091109
>Array : ArrayConstructor
11101110

11111111
Array.isArray : function (value) { return Object.prototype.toString.call(value) === '[object Array]'; };
1112-
>Array.isArray : (arg: any) => arg is any[]
1112+
>Array.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
11131113
>Array : ArrayConstructor
1114-
>isArray : (arg: any) => arg is any[]
1114+
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? readonly any[] : any[]
11151115
>function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : (value: any) => boolean
11161116
>value : any
11171117
>Object.prototype.toString.call(value) === '[object Array]' : boolean

0 commit comments

Comments
 (0)