Skip to content

Commit 289b0c8

Browse files
committed
A second attempt at readonly array support persisting through isArray
1 parent a894f8a commit 289b0c8

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/lib.es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ interface ArrayConstructor {
14081408
(arrayLength?: number): any[];
14091409
<T>(arrayLength: number): T[];
14101410
<T>(...items: T[]): T[];
1411-
isArray(arg: any): arg is any[];
1411+
isArray(arg: any): x is readonly unknown[];
14121412
readonly prototype: any[];
14131413
}
14141414

src/compiler/checker.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22999,11 +22999,16 @@ namespace ts {
2299922999
}
2300023000
}
2300123001

23002-
// If the candidate type is a subtype of the target type, narrow to the candidate type,
23003-
// if the target type is a subtype of the candidate type, narrow to the target type,
23004-
// otherwise, narrow to an intersection of the two types.
23005-
return isTypeSubtypeOf(candidate, type) ? candidate : isTypeSubtypeOf(type, candidate) ? type : getIntersectionType([type, candidate]);
23006-
}
23002+
// If the candidate type is a subtype of the target type, narrow to the candidate type.
23003+
// Otherwise, if the target type is assignable to the candidate type, keep the target type.
23004+
// Otherwise, if the candidate type is assignable to the target type, narrow to the candidate
23005+
// type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
23006+
// two types.
23007+
return isTypeSubtypeOf(candidate, type) ? candidate :
23008+
isTypeAssignableTo(type, candidate) ? type :
23009+
isTypeAssignableTo(candidate, type) ? candidate :
23010+
getIntersectionType([type, candidate]);
23011+
}
2300723012

2300823013
function narrowTypeByCallExpression(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
2300923014
if (hasMatchingArgument(callExpression, reference)) {

0 commit comments

Comments
 (0)