Skip to content

Commit e81d845

Browse files
committed
Add tests and the new isArray definition
1 parent 636bc9d commit e81d845

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/lib/es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ interface ArrayConstructor {
13761376
(arrayLength?: number): any[];
13771377
<T>(arrayLength: number): T[];
13781378
<T>(...items: T[]): T[];
1379-
isArray(arg: any): arg is any[];
1379+
isArray<T>(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[];
13801380
readonly prototype: any[];
13811381
}
13821382

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// https://github.com/microsoft/TypeScript/issues/31155
2+
13
declare const MyArray: {
24
isArray<T>(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[];
35
};
@@ -7,23 +9,23 @@ declare const b: string[] | string;
79
declare const c: unknown;
810

911
if (MyArray.isArray(a)) {
10-
a;
12+
a; // readonly string[]
1113
}
1214
else {
13-
a;
15+
a; // string
1416
}
15-
a;
17+
a; // readonly string[] | string;
1618

1719
if (MyArray.isArray(b)) {
18-
b;
20+
b; // string[] | string;
1921
}
2022
else {
21-
b;
23+
b; // string
2224
}
23-
b;
25+
b; // string[] | string;
2426

2527
if (MyArray.isArray(c)) {
26-
c;
28+
c; // any[]
2729
}
2830

2931

@@ -33,22 +35,22 @@ function f<T>(x: T) {
3335
const c: T = null!;
3436

3537
if (MyArray.isArray(a)) {
36-
a;
38+
a; // readonly T[]
3739
}
3840
else {
39-
a;
41+
a; // string
4042
}
41-
a;
43+
a; // readonly T[] | string;
4244

4345
if (MyArray.isArray(b)) {
44-
b;
46+
b; // T[]
4547
}
4648
else {
47-
b;
49+
b; // string
4850
}
4951
b;
5052

5153
if (MyArray.isArray(c)) {
52-
c;
54+
c; // T & (T extends readonly any[] ? readonly any[] : any[])
5355
}
5456
}

0 commit comments

Comments
 (0)