Skip to content

Commit 6c2c564

Browse files
committed
Revert isArrayLikeType
1 parent b1a582c commit 6c2c564

5 files changed

+5
-39
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25480,11 +25480,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2548025480

2548125481
function isArrayLikeType(type: Type): boolean {
2548225482
// A type is array-like if it is a reference to the global Array or global ReadonlyArray type,
25483-
// or if it is not the undefined or null type and if it is assignable to ReadonlyArray<any>.
25484-
// When Array doesn't exist (noLib), we can't determine array-likeness.
25485-
if (anyReadonlyArrayType === emptyObjectType) {
25486-
return false;
25487-
}
25483+
// or if it is not the undefined or null type and if it is assignable to ReadonlyArray<any>
2548825484
return isArrayType(type) || !(type.flags & TypeFlags.Nullable) && isTypeAssignableTo(type, anyReadonlyArrayType);
2548925485
}
2549025486

tests/baselines/reference/arrayIterationLibES5TargetDifferent(nolib=true,target=es2015).errors.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ error TS2318: Cannot find global type 'Object'.
99
error TS2318: Cannot find global type 'RegExp'.
1010
error TS2318: Cannot find global type 'String'.
1111
error TS5053: Option 'lib' cannot be specified with option 'noLib'.
12-
arrayIterationLibES5TargetDifferent.ts(3,17): error TS2495: Type '{}' is not an array type or a string type.
13-
arrayIterationLibES5TargetDifferent.ts(15,17): error TS2495: Type 'number' is not an array type or a string type.
14-
arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string; }' is not an array type or a string type.
1512

1613

1714
!!! error TS2318: Cannot find global type 'Array'.
@@ -25,12 +22,10 @@ arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string
2522
!!! error TS2318: Cannot find global type 'RegExp'.
2623
!!! error TS2318: Cannot find global type 'String'.
2724
!!! error TS5053: Option 'lib' cannot be specified with option 'noLib'.
28-
==== arrayIterationLibES5TargetDifferent.ts (3 errors) ====
25+
==== arrayIterationLibES5TargetDifferent.ts (0 errors) ====
2926
declare function log(message?: any): void;
3027

3128
for (const x of [1, 2, 3]) {
32-
~~~~~~~~~
33-
!!! error TS2495: Type '{}' is not an array type or a string type.
3429
log(x);
3530
}
3631

@@ -43,15 +38,11 @@ arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string
4338
declare const aNumber: number;
4439

4540
for (const x of aNumber) {
46-
~~~~~~~
47-
!!! error TS2495: Type 'number' is not an array type or a string type.
4841
log(x);
4942
}
5043

5144
declare const anObject: { foo: string };
5245

5346
for (const x of anObject) {
54-
~~~~~~~~
55-
!!! error TS2495: Type '{ foo: string; }' is not an array type or a string type.
5647
log(x);
5748
}

tests/baselines/reference/arrayIterationLibES5TargetDifferent(nolib=true,target=es5).errors.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ error TS2318: Cannot find global type 'Object'.
99
error TS2318: Cannot find global type 'RegExp'.
1010
error TS2318: Cannot find global type 'String'.
1111
error TS5053: Option 'lib' cannot be specified with option 'noLib'.
12-
arrayIterationLibES5TargetDifferent.ts(3,17): error TS2495: Type '{}' is not an array type or a string type.
13-
arrayIterationLibES5TargetDifferent.ts(15,17): error TS2495: Type 'number' is not an array type or a string type.
14-
arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string; }' is not an array type or a string type.
1512

1613

1714
!!! error TS2318: Cannot find global type 'Array'.
@@ -25,12 +22,10 @@ arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string
2522
!!! error TS2318: Cannot find global type 'RegExp'.
2623
!!! error TS2318: Cannot find global type 'String'.
2724
!!! error TS5053: Option 'lib' cannot be specified with option 'noLib'.
28-
==== arrayIterationLibES5TargetDifferent.ts (3 errors) ====
25+
==== arrayIterationLibES5TargetDifferent.ts (0 errors) ====
2926
declare function log(message?: any): void;
3027

3128
for (const x of [1, 2, 3]) {
32-
~~~~~~~~~
33-
!!! error TS2495: Type '{}' is not an array type or a string type.
3429
log(x);
3530
}
3631

@@ -43,15 +38,11 @@ arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string
4338
declare const aNumber: number;
4439

4540
for (const x of aNumber) {
46-
~~~~~~~
47-
!!! error TS2495: Type 'number' is not an array type or a string type.
4841
log(x);
4942
}
5043

5144
declare const anObject: { foo: string };
5245

5346
for (const x of anObject) {
54-
~~~~~~~~
55-
!!! error TS2495: Type '{ foo: string; }' is not an array type or a string type.
5647
log(x);
5748
}

tests/baselines/reference/arrayIterationLibES5TargetDifferent(nolib=true,target=esnext).errors.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ error TS2318: Cannot find global type 'Object'.
99
error TS2318: Cannot find global type 'RegExp'.
1010
error TS2318: Cannot find global type 'String'.
1111
error TS5053: Option 'lib' cannot be specified with option 'noLib'.
12-
arrayIterationLibES5TargetDifferent.ts(3,17): error TS2495: Type '{}' is not an array type or a string type.
13-
arrayIterationLibES5TargetDifferent.ts(15,17): error TS2495: Type 'number' is not an array type or a string type.
14-
arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string; }' is not an array type or a string type.
1512

1613

1714
!!! error TS2318: Cannot find global type 'Array'.
@@ -25,12 +22,10 @@ arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string
2522
!!! error TS2318: Cannot find global type 'RegExp'.
2623
!!! error TS2318: Cannot find global type 'String'.
2724
!!! error TS5053: Option 'lib' cannot be specified with option 'noLib'.
28-
==== arrayIterationLibES5TargetDifferent.ts (3 errors) ====
25+
==== arrayIterationLibES5TargetDifferent.ts (0 errors) ====
2926
declare function log(message?: any): void;
3027

3128
for (const x of [1, 2, 3]) {
32-
~~~~~~~~~
33-
!!! error TS2495: Type '{}' is not an array type or a string type.
3429
log(x);
3530
}
3631

@@ -43,15 +38,11 @@ arrayIterationLibES5TargetDifferent.ts(21,17): error TS2495: Type '{ foo: string
4338
declare const aNumber: number;
4439

4540
for (const x of aNumber) {
46-
~~~~~~~
47-
!!! error TS2495: Type 'number' is not an array type or a string type.
4841
log(x);
4942
}
5043

5144
declare const anObject: { foo: string };
5245

5346
for (const x of anObject) {
54-
~~~~~~~~
55-
!!! error TS2495: Type '{ foo: string; }' is not an array type or a string type.
5647
log(x);
5748
}

tests/baselines/reference/noCrashOnNoLib.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ error TS2318: Cannot find global type 'Number'.
66
error TS2318: Cannot find global type 'Object'.
77
error TS2318: Cannot find global type 'RegExp'.
88
error TS2318: Cannot find global type 'String'.
9-
noCrashOnNoLib.ts(4,15): error TS2461: Type '{}' is not an array type.
109

1110

1211
!!! error TS2318: Cannot find global type 'Array'.
@@ -17,12 +16,10 @@ noCrashOnNoLib.ts(4,15): error TS2461: Type '{}' is not an array type.
1716
!!! error TS2318: Cannot find global type 'Object'.
1817
!!! error TS2318: Cannot find global type 'RegExp'.
1918
!!! error TS2318: Cannot find global type 'String'.
20-
==== noCrashOnNoLib.ts (1 errors) ====
19+
==== noCrashOnNoLib.ts (0 errors) ====
2120
export function f() {
2221
let e: {}[] = [];
2322
while (true) {
2423
e = [...(e || [])];
25-
~~~~~~~~~
26-
!!! error TS2461: Type '{}' is not an array type.
2724
}
2825
}

0 commit comments

Comments
 (0)