mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
106 lines
5.9 KiB
Plaintext
106 lines
5.9 KiB
Plaintext
generatorAssignability.ts(10,5): error TS2764: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array spread will always send 'undefined'.
|
|
generatorAssignability.ts(14,5): error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
generatorAssignability.ts(18,5): error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
generatorAssignability.ts(22,1): error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
generatorAssignability.ts(26,1): error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
generatorAssignability.ts(30,11): error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'string', but for-of will always send 'undefined'.
|
|
generatorAssignability.ts(35,21): error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'string', but for-of will always send 'undefined'.
|
|
generatorAssignability.ts(39,21): error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'string', but for-of will always send 'undefined'.
|
|
generatorAssignability.ts(45,12): error TS2766: Cannot delegate iteration to value because the 'next' method of its iterator expects type 'string', but the containing generator will always send 'boolean'.
|
|
generatorAssignability.ts(51,12): error TS2766: Cannot delegate iteration to value because the 'next' method of its iterator expects type 'string', but the containing generator will always send 'boolean'.
|
|
generatorAssignability.ts(55,12): error TS2766: Cannot delegate iteration to value because the 'next' method of its iterator expects type 'string', but the containing generator will always send 'boolean'.
|
|
|
|
|
|
==== generatorAssignability.ts (11 errors) ====
|
|
declare let _: any;
|
|
declare const g1: Generator<number, void, string>;
|
|
declare const g2: Generator<number, void, undefined>;
|
|
declare const g3: Generator<number, void, boolean>;
|
|
declare const g4: AsyncGenerator<number, void, string>;
|
|
declare const g5: AsyncGenerator<number, void, undefined>;
|
|
declare const g6: AsyncGenerator<number, void, boolean>;
|
|
|
|
// spread iterable
|
|
[...g1]; // error
|
|
~~
|
|
!!! error TS2764: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array spread will always send 'undefined'.
|
|
[...g2]; // ok
|
|
|
|
// binding pattern over iterable
|
|
let [x1] = g1; // error
|
|
~~~~
|
|
!!! error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
let [x2] = g2; // ok
|
|
|
|
// binding rest pattern over iterable
|
|
let [...y1] = g1; // error
|
|
~~~~~~~
|
|
!!! error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
let [...y2] = g2; // ok
|
|
|
|
// assignment pattern over iterable
|
|
[_] = g1; // error
|
|
~~~
|
|
!!! error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
[_] = g2; // ok
|
|
|
|
// assignment rest pattern over iterable
|
|
[..._] = g1; // error
|
|
~~~~~~
|
|
!!! error TS2765: Cannot iterate value because the 'next' method of its iterator expects type 'string', but array destructuring will always send 'undefined'.
|
|
[..._] = g2; // ok
|
|
|
|
// for-of over iterable
|
|
for (_ of g1); // error
|
|
~~
|
|
!!! error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'string', but for-of will always send 'undefined'.
|
|
for (_ of g2); // ok
|
|
|
|
async function asyncfn() {
|
|
// for-await-of over iterable
|
|
for await (_ of g1); // error
|
|
~~
|
|
!!! error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'string', but for-of will always send 'undefined'.
|
|
for await (_ of g2); // ok
|
|
|
|
// for-await-of over asynciterable
|
|
for await (_ of g4); // error
|
|
~~
|
|
!!! error TS2763: Cannot iterate value because the 'next' method of its iterator expects type 'string', but for-of will always send 'undefined'.
|
|
for await (_ of g5); // ok
|
|
}
|
|
|
|
function* f1(): Generator<number, void, boolean> {
|
|
// yield* over iterable
|
|
yield* g1; // error
|
|
~~
|
|
!!! error TS2766: Cannot delegate iteration to value because the 'next' method of its iterator expects type 'string', but the containing generator will always send 'boolean'.
|
|
yield* g3; // ok
|
|
}
|
|
|
|
async function* f2(): AsyncGenerator<number, void, boolean> {
|
|
// yield* over iterable
|
|
yield* g1; // error
|
|
~~
|
|
!!! error TS2766: Cannot delegate iteration to value because the 'next' method of its iterator expects type 'string', but the containing generator will always send 'boolean'.
|
|
yield* g3; // ok
|
|
|
|
// yield* over asynciterable
|
|
yield* g4; // error
|
|
~~
|
|
!!! error TS2766: Cannot delegate iteration to value because the 'next' method of its iterator expects type 'string', but the containing generator will always send 'boolean'.
|
|
yield* g6; // ok
|
|
}
|
|
|
|
async function f3() {
|
|
const syncGenerator = function*() {
|
|
yield 1;
|
|
yield 2;
|
|
};
|
|
|
|
const o = {[Symbol.asyncIterator]: syncGenerator};
|
|
|
|
for await (const x of o) {
|
|
}
|
|
}
|
|
|