Skip to content
Closed
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
26 changes: 23 additions & 3 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6081,6 +6081,29 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
if IsTypeAny(t) {
return IterationTypes{c.anyType, c.anyType, c.anyType}
}
if t.flags&TypeFlagsUnion != 0 {
key := IterationTypesKey{typeId: t.id, use: use & IterationUseCacheFlags}
if cached, ok := c.iterationTypesCache[key]; ok {
if errorNode == nil || cached.hasTypes() {
return cached
}
}
var allIterationTypes []IterationTypes
for _, constituent := range t.Types() {
iterationTypes := c.getIterationTypesOfIterable(constituent, use, nil)
if !iterationTypes.hasTypes() {
if errorNode != nil {
c.reportTypeNotIterableError(errorNode, t, use&IterationUseAllowsAsyncIterablesFlag != 0)
}
c.iterationTypesCache[key] = IterationTypes{}
return IterationTypes{}
}
allIterationTypes = append(allIterationTypes, iterationTypes)
}
result := c.combineIterationTypes(allIterationTypes)
c.iterationTypesCache[key] = result
return result
}
key := IterationTypesKey{typeId: t.id, use: use & IterationUseCacheFlags}
// If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
// In addition, we should not cache any new results for this call.
Expand All @@ -6099,9 +6122,6 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
}

func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node, noCache bool) IterationTypes {
if t.flags&TypeFlagsUnion != 0 {
return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode, noCache) }))
}
if use&IterationUseAllowsAsyncIterablesFlag != 0 {
iterationTypes := c.getIterationTypesOfIterableFast(t, c.asyncIterationTypesResolver)
if iterationTypes.hasTypes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
regExpIndicesArrayDestructuring.ts(2,6): error TS2488: Type '[number, number] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.


==== regExpIndicesArrayDestructuring.ts (1 errors) ====
declare let indices: RegExpIndicesArray;
let [[x, y]] = indices;
~~~~~~
!!! error TS2488: Type '[number, number] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [tests/cases/compiler/regExpIndicesArrayDestructuring.ts] ////

=== regExpIndicesArrayDestructuring.ts ===
declare let indices: RegExpIndicesArray;
>indices : Symbol(indices, Decl(regExpIndicesArrayDestructuring.ts, 0, 11))
>RegExpIndicesArray : Symbol(RegExpIndicesArray, Decl(lib.es2022.regexp.d.ts, --, --))

let [[x, y]] = indices;
>x : Symbol(x, Decl(regExpIndicesArrayDestructuring.ts, 1, 6))
>y : Symbol(y, Decl(regExpIndicesArrayDestructuring.ts, 1, 8))
>indices : Symbol(indices, Decl(regExpIndicesArrayDestructuring.ts, 0, 11))

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/regExpIndicesArrayDestructuring.ts] ////

=== regExpIndicesArrayDestructuring.ts ===
declare let indices: RegExpIndicesArray;
>indices : RegExpIndicesArray

let [[x, y]] = indices;
>x : any
>y : any
>indices : RegExpIndicesArray

Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
noImplicitAnyLoopCrash.ts(4,16): error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
noImplicitAnyLoopCrash.ts(4,19): error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
noImplicitAnyLoopCrash.ts(4,19): error TS2488: Type 'undefined' must have a '[Symbol.iterator]()' method that returns an iterator.
noImplicitAnyLoopCrash.ts(4,19): error TS2488: Type 'number | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.


==== noImplicitAnyLoopCrash.ts (3 errors) ====
==== noImplicitAnyLoopCrash.ts (2 errors) ====
let foo = () => {};
let bar;
while (1) {
bar = ~foo(...bar);
~~~~~~
!!! error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
~~~
!!! error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
~~~
!!! error TS2488: Type 'undefined' must have a '[Symbol.iterator]()' method that returns an iterator.
!!! error TS2488: Type 'number | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ES5For-of30.ts(3,6): error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
ES5For-of30.ts(3,6): error TS2488: Type 'string | number' must have a '[Symbol.iterator]()' method that returns an iterator.
ES5For-of30.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'.
ES5For-of30.ts(3,14): error TS2322: Type 'string' is not assignable to type 'number'.

Expand All @@ -8,7 +8,7 @@ ES5For-of30.ts(3,14): error TS2322: Type 'string' is not assignable to type 'num
var tuple: [number, string] = [2, "3"];
for ([a = 1, b = ""] of tuple) {
~~~~~~~~~~~~~~~
!!! error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
!!! error TS2488: Type 'string | number' must have a '[Symbol.iterator]()' method that returns an iterator.
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
~
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ES5For-ofTypeCheck7.ts(2,15): error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
ES5For-ofTypeCheck7.ts(2,15): error TS2488: Type 'string | number' must have a '[Symbol.iterator]()' method that returns an iterator.


==== ES5For-ofTypeCheck7.ts (1 errors) ====
declare var union: string | number;
for (var v of union) { }
~~~~~
!!! error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
!!! error TS2488: Type 'string | number' must have a '[Symbol.iterator]()' method that returns an iterator.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ declare var union: string | number;
>union : string | number

for (var v of union) { }
>v : string
>v : any
>union : string | number

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
ES5For-ofTypeCheck9.ts(2,15): error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
ES5For-ofTypeCheck9.ts(2,15): error TS2488: Type 'symbol' must have a '[Symbol.iterator]()' method that returns an iterator.
ES5For-ofTypeCheck9.ts(2,15): error TS2488: Type 'string | number | symbol | string[]' must have a '[Symbol.iterator]()' method that returns an iterator.


==== ES5For-ofTypeCheck9.ts (2 errors) ====
==== ES5For-ofTypeCheck9.ts (1 errors) ====
declare var union: string | string[] | number | symbol;
for (let v of union) { }
~~~~~
!!! error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.
~~~~~
!!! error TS2488: Type 'symbol' must have a '[Symbol.iterator]()' method that returns an iterator.
!!! error TS2488: Type 'string | number | symbol | string[]' must have a '[Symbol.iterator]()' method that returns an iterator.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ declare var union: string | string[] | number | symbol;
>union : string | number | symbol | string[]

for (let v of union) { }
>v : string
>v : any
>union : string | number | symbol | string[]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
destructuringArrayBindingPatternAndAssignment4.ts(5,7): error TS2488: Type 'null' must have a '[Symbol.iterator]()' method that returns an iterator.
destructuringArrayBindingPatternAndAssignment4.ts(5,7): error TS2488: Type 'number[] | null' must have a '[Symbol.iterator]()' method that returns an iterator.


==== destructuringArrayBindingPatternAndAssignment4.ts (1 errors) ====
Expand All @@ -8,5 +8,5 @@ destructuringArrayBindingPatternAndAssignment4.ts(5,7): error TS2488: Type 'null
declare const data: number[] | null;
const [value] = data; // Error
~~~~~~~
!!! error TS2488: Type 'null' must have a '[Symbol.iterator]()' method that returns an iterator.
!!! error TS2488: Type 'number[] | null' must have a '[Symbol.iterator]()' method that returns an iterator.

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@
+++ new.destructuringArrayBindingPatternAndAssignment4(target=es2015).errors.txt
@@= skipped -0, +0 lines =@@
-error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
-destructuringArrayBindingPatternAndAssignment4.ts(5,7): error TS2488: Type 'number[] | null' must have a '[Symbol.iterator]()' method that returns an iterator.
-
-
destructuringArrayBindingPatternAndAssignment4.ts(5,7): error TS2488: Type 'number[] | null' must have a '[Symbol.iterator]()' method that returns an iterator.


-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
+destructuringArrayBindingPatternAndAssignment4.ts(5,7): error TS2488: Type 'null' must have a '[Symbol.iterator]()' method that returns an iterator.
+
+
==== destructuringArrayBindingPatternAndAssignment4.ts (1 errors) ====
// #35497

@@= skipped -9, +7 lines =@@
declare const data: number[] | null;
const [value] = data; // Error
~~~~~~~
-!!! error TS2488: Type 'number[] | null' must have a '[Symbol.iterator]()' method that returns an iterator.
+!!! error TS2488: Type 'null' must have a '[Symbol.iterator]()' method that returns an iterator.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ declare const data: number[] | null;
>data : number[] | null

const [value] = data; // Error
>value : number
>value : any
>data : number[] | null

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @target: esnext
// @noEmit: true

declare let indices: RegExpIndicesArray;
let [[x, y]] = indices;