Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,7 @@ interface ArrayConstructor {
(arrayLength?: number): any[];
<T>(arrayLength: number): T[];
<T>(...items: T[]): T[];
isArray(arg: readonly any[] | any): arg is readonly any[];
isArray(arg: any): arg is any[];
readonly prototype: any[];
}
Expand Down
26 changes: 26 additions & 0 deletions tests/cases/compiler/arrayIsArrayReadonlyNarrowing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @strict: true

function test1(x: readonly string[] | string) {
if (Array.isArray(x)) {
x; // should be readonly string[]
}
}

function test2(x: readonly number[] | number) {
if (Array.isArray(x)) {
x; // should be readonly number[]
x[0]; // should be number
}
}

function test3(x: string[] | string) {
if (Array.isArray(x)) {
x; // should still be string[] (not readonly)
}
}

function test4(x: unknown) {
if (Array.isArray(x)) {
x; // should still be any[] (existing behavior)
}
}