Skip to content

Commit 51be560

Browse files
committed
Fix return value and error reporting for getIterationTypesOfMethod
1 parent c0072aa commit 51be560

File tree

7 files changed

+125
-59
lines changed

7 files changed

+125
-59
lines changed

src/compiler/checker.ts

Lines changed: 109 additions & 45 deletions
Large diffs are not rendered by default.

tests/baselines/reference/for-of16.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(8,11): error TS2489: An iterator must have a 'next()' method.
1+
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(8,11): error TS2488: Type 'StringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
22

33

44
==== tests/cases/conformance/es6/for-ofStatements/for-of16.ts (1 errors) ====
@@ -11,4 +11,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of16.ts(8,11): error TS2489: An
1111
var v: string;
1212
for (v of new StringIterator) { } // Should fail
1313
~~~~~~~~~~~~~~~~~~
14-
!!! error TS2489: An iterator must have a 'next()' method.
14+
!!! error TS2488: Type 'StringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
15+
!!! related TS2489 tests/cases/conformance/es6/for-ofStatements/for-of16.ts:8:11: An iterator must have a 'next()' method.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): error TS2322: Type 'Generator<(x: any) => any, void, any>' is not assignable to type '() => Iterable<(x: string) => number>'.
2-
Type 'Generator<(x: any) => any, void, any>' provides no match for the signature '(): Iterable<(x: string) => number>'.
1+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): error TS2322: Type 'Generator<(x: any) => any, void, unknown>' is not assignable to type '() => Iterable<(x: string) => number>'.
2+
Type 'Generator<(x: any) => any, void, unknown>' provides no match for the signature '(): Iterable<(x: string) => number>'.
33

44

55
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts (1 errors) ====
@@ -10,6 +10,6 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): erro
1010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1111
} ()
1212
~~~~~~~~
13-
!!! error TS2322: Type 'Generator<(x: any) => any, void, any>' is not assignable to type '() => Iterable<(x: string) => number>'.
14-
!!! error TS2322: Type 'Generator<(x: any) => any, void, any>' provides no match for the signature '(): Iterable<(x: string) => number>'.
13+
!!! error TS2322: Type 'Generator<(x: any) => any, void, unknown>' is not assignable to type '() => Iterable<(x: string) => number>'.
14+
!!! error TS2322: Type 'Generator<(x: any) => any, void, unknown>' provides no match for the signature '(): Iterable<(x: string) => number>'.
1515
}

tests/baselines/reference/generatorTypeCheck31.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ function* g2(): Iterator<() => Iterable<(x: string) => number>> {
55

66
yield function* () {
77
>yield function* () { yield x => x.length; } () : undefined
8-
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, any>
9-
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, any>
8+
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, unknown>
9+
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, unknown>
1010

1111
yield x => x.length;
1212
>yield x => x.length : any
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts(1,17): error TS2322: Type 'Generator<any, any, any>' is not assignable to type 'number'.
1+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts(1,17): error TS2322: Type 'Generator<any, any, unknown>' is not assignable to type 'number'.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts (1 errors) ====
55
function* g1(): number { }
66
~~~~~~
7-
!!! error TS2322: Type 'Generator<any, any, any>' is not assignable to type 'number'.
7+
!!! error TS2322: Type 'Generator<any, any, unknown>' is not assignable to type 'number'.

tests/baselines/reference/iteratorSpreadInArray10.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts(7,17): error TS2489: An iterator must have a 'next()' method.
1+
tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts(7,17): error TS2488: Type 'SymbolIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
22

33

44
==== tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts (1 errors) ====
@@ -10,4 +10,5 @@ tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts(7,17): error TS248
1010

1111
var array = [...new SymbolIterator];
1212
~~~~~~~~~~~~~~~~~~
13-
!!! error TS2489: An iterator must have a 'next()' method.
13+
!!! error TS2488: Type 'SymbolIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
14+
!!! related TS2489 tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts:7:17: An iterator must have a 'next()' method.

tests/baselines/reference/types.asyncGenerators.es2018.2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
3636
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(59,12): error TS2322: Type 'string' is not assignable to type 'number'.
3737
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(62,12): error TS2322: Type 'string' is not assignable to type 'number'.
3838
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(64,42): error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<number, any, undefined>' but required in type 'IterableIterator<number>'.
39-
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(67,42): error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, any>' but required in type 'Iterable<number>'.
39+
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(67,42): error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, unknown>' but required in type 'Iterable<number>'.
4040
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(70,42): error TS2322: Type 'AsyncGenerator<number, any, undefined>' is not assignable to type 'Iterator<number, any, undefined>'.
4141
The types returned by 'next(...)' are incompatible between these types.
4242
Type 'Promise<IteratorResult<number, any>>' is not assignable to type 'IteratorResult<number, any>'.
@@ -173,7 +173,7 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
173173
}
174174
async function * explicitReturnType11(): Iterable<number> {
175175
~~~~~~~~~~~~~~~~
176-
!!! error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, any>' but required in type 'Iterable<number>'.
176+
!!! error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, unknown>' but required in type 'Iterable<number>'.
177177
!!! related TS2728 /.ts/lib.es2015.iterable.d.ts:51:5: '[Symbol.iterator]' is declared here.
178178
yield 1;
179179
}

0 commit comments

Comments
 (0)