diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 85f2f84c677..7105e3605aa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18815,6 +18815,17 @@ namespace ts { return false; } + function getContextualIterationType(kind: IterationTypeKind, functionDecl: SignatureDeclaration): Type | undefined { + const isAsync = !!(getFunctionFlags(functionDecl) & FunctionFlags.Async); + const contextualReturnType = getContextualReturnType(functionDecl); + if (contextualReturnType) { + return getIterationTypeOfGeneratorFunctionReturnType(kind, contextualReturnType, isAsync) + || undefined; + } + + return undefined; + } + function getContextualReturnType(functionDecl: SignatureDeclaration): Type | undefined { // If the containing function has a return type annotation, is a constructor, or is a get accessor whose // corresponding set accessor has a type annotation, return statements in the function are contextually typed @@ -23480,7 +23491,11 @@ namespace ts { } if (isGenerator) { - return createGeneratorReturnType(yieldType || neverType, returnType || fallbackReturnType, nextType || unknownType, isAsync); + return createGeneratorReturnType( + yieldType || neverType, + returnType || fallbackReturnType, + nextType || getContextualIterationType(IterationTypeKind.Next, func) || unknownType, + isAsync); } else { // From within an async function you can return either a non-promise value or a promise. Any @@ -24841,13 +24856,7 @@ namespace ts { || anyType; } - const contextualReturnType = getContextualReturnType(func); - if (contextualReturnType) { - return getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Next, contextualReturnType, isAsync) - || anyType; - } - - return anyType; + return getContextualIterationType(IterationTypeKind.Next, func) || anyType; } function checkConditionalExpression(node: ConditionalExpression, checkMode?: CheckMode): Type { diff --git a/tests/baselines/reference/generatorTypeCheck28.types b/tests/baselines/reference/generatorTypeCheck28.types index 6921c946a39..abd66af518e 100644 --- a/tests/baselines/reference/generatorTypeCheck28.types +++ b/tests/baselines/reference/generatorTypeCheck28.types @@ -5,10 +5,10 @@ function* g(): IterableIterator<(x: string) => number> { yield * { >yield * { *[Symbol.iterator]() { yield x => x.length; } } : void ->{ *[Symbol.iterator]() { yield x => x.length; } } : { [Symbol.iterator](): Generator<(x: string) => number, void, unknown>; } +>{ *[Symbol.iterator]() { yield x => x.length; } } : { [Symbol.iterator](): Generator<(x: string) => number, void, undefined>; } *[Symbol.iterator]() { ->[Symbol.iterator] : () => Generator<(x: string) => number, void, unknown> +>[Symbol.iterator] : () => Generator<(x: string) => number, void, undefined> >Symbol.iterator : symbol >Symbol : SymbolConstructor >iterator : symbol diff --git a/tests/baselines/reference/generatorTypeCheck45.types b/tests/baselines/reference/generatorTypeCheck45.types index 18d3e9a5fc2..f8f88191e56 100644 --- a/tests/baselines/reference/generatorTypeCheck45.types +++ b/tests/baselines/reference/generatorTypeCheck45.types @@ -11,7 +11,7 @@ foo("", function* () { yield x => x.length }, p => undefined); // T is fixed, sh >foo("", function* () { yield x => x.length }, p => undefined) : string >foo : (x: T, fun: () => Iterator<(x: T) => U, any, undefined>, fun2: (y: U) => T) => T >"" : "" ->function* () { yield x => x.length } : () => Generator<(x: string) => number, void, unknown> +>function* () { yield x => x.length } : () => Generator<(x: string) => number, void, undefined> >yield x => x.length : undefined >x => x.length : (x: string) => number >x : string diff --git a/tests/baselines/reference/generatorTypeCheck46.types b/tests/baselines/reference/generatorTypeCheck46.types index 283188193b7..3beb73892ce 100644 --- a/tests/baselines/reference/generatorTypeCheck46.types +++ b/tests/baselines/reference/generatorTypeCheck46.types @@ -11,14 +11,14 @@ foo("", function* () { >foo("", function* () { yield* { *[Symbol.iterator]() { yield x => x.length } }}, p => undefined) : string >foo : (x: T, fun: () => Iterable<(x: T) => U>, fun2: (y: U) => T) => T >"" : "" ->function* () { yield* { *[Symbol.iterator]() { yield x => x.length } }} : () => Generator<(x: string) => number, void, unknown> +>function* () { yield* { *[Symbol.iterator]() { yield x => x.length } }} : () => Generator<(x: string) => number, void, undefined> yield* { >yield* { *[Symbol.iterator]() { yield x => x.length } } : void ->{ *[Symbol.iterator]() { yield x => x.length } } : { [Symbol.iterator](): Generator<(x: string) => number, void, unknown>; } +>{ *[Symbol.iterator]() { yield x => x.length } } : { [Symbol.iterator](): Generator<(x: string) => number, void, undefined>; } *[Symbol.iterator]() { ->[Symbol.iterator] : () => Generator<(x: string) => number, void, unknown> +>[Symbol.iterator] : () => Generator<(x: string) => number, void, undefined> >Symbol.iterator : symbol >Symbol : SymbolConstructor >iterator : symbol diff --git a/tests/baselines/reference/generatorTypeCheck62.types b/tests/baselines/reference/generatorTypeCheck62.types index ed957295c31..52eb65fbb63 100644 --- a/tests/baselines/reference/generatorTypeCheck62.types +++ b/tests/baselines/reference/generatorTypeCheck62.types @@ -12,7 +12,7 @@ export function strategy(stratName: string, gen: (a: T >a : T return function*(state) { ->function*(state) { for (const next of gen(state)) { if (next) { next.lastStrategyApplied = stratName; } yield next; } } : (state: T) => Generator +>function*(state) { for (const next of gen(state)) { if (next) { next.lastStrategyApplied = stratName; } yield next; } } : (state: T) => Generator >state : T for (const next of gen(state)) { @@ -53,7 +53,7 @@ export const Nothing1: Strategy = strategy("Nothing", function*(state: St >strategy("Nothing", function*(state: State) { return state;}) : (a: State) => IterableIterator >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function*(state: State) { return state;} : (state: State) => Generator +>function*(state: State) { return state;} : (state: State) => Generator >state : State return state; @@ -66,7 +66,7 @@ export const Nothing2: Strategy = strategy("Nothing", function*(state: St >strategy("Nothing", function*(state: State) { yield state;}) : (a: State) => IterableIterator >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function*(state: State) { yield state;} : (state: State) => Generator +>function*(state: State) { yield state;} : (state: State) => Generator >state : State yield state; @@ -80,7 +80,7 @@ export const Nothing3: Strategy = strategy("Nothing", function* (state: S >strategy("Nothing", function* (state: State) { yield ; return state;}) : (a: any) => IterableIterator >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function* (state: State) { yield ; return state;} : (state: State) => Generator +>function* (state: State) { yield ; return state;} : (state: State) => Generator >state : State yield ; diff --git a/tests/baselines/reference/generatorTypeCheck63.errors.txt b/tests/baselines/reference/generatorTypeCheck63.errors.txt index f77488edc4d..60dfb089822 100644 --- a/tests/baselines/reference/generatorTypeCheck63.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck63.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): error TS2345: Argument of type '(state: State) => Generator' is not assignable to parameter of type '(a: State) => IterableIterator'. - Type 'Generator' is not assignable to type 'IterableIterator'. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): error TS2345: Argument of type '(state: State) => Generator' is not assignable to parameter of type '(a: State) => IterableIterator'. + Type 'Generator' is not assignable to type 'IterableIterator'. Types of property 'next' are incompatible. - Type '(...args: [] | [unknown]) => IteratorResult' is not assignable to type '(...args: [] | [undefined]) => IteratorResult'. + Type '(...args: [] | [undefined]) => IteratorResult' is not assignable to type '(...args: [] | [undefined]) => IteratorResult'. Type 'IteratorResult' is not assignable to type 'IteratorResult'. Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'. @@ -34,10 +34,10 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): err export const Nothing: Strategy = strategy("Nothing", function* (state: State) { ~~~~~~~~ -!!! error TS2345: Argument of type '(state: State) => Generator' is not assignable to parameter of type '(a: State) => IterableIterator'. -!!! error TS2345: Type 'Generator' is not assignable to type 'IterableIterator'. +!!! error TS2345: Argument of type '(state: State) => Generator' is not assignable to parameter of type '(a: State) => IterableIterator'. +!!! error TS2345: Type 'Generator' is not assignable to type 'IterableIterator'. !!! error TS2345: Types of property 'next' are incompatible. -!!! error TS2345: Type '(...args: [] | [unknown]) => IteratorResult' is not assignable to type '(...args: [] | [undefined]) => IteratorResult'. +!!! error TS2345: Type '(...args: [] | [undefined]) => IteratorResult' is not assignable to type '(...args: [] | [undefined]) => IteratorResult'. !!! error TS2345: Type 'IteratorResult' is not assignable to type 'IteratorResult'. !!! error TS2345: Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. !!! error TS2345: Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'. diff --git a/tests/baselines/reference/generatorTypeCheck63.types b/tests/baselines/reference/generatorTypeCheck63.types index 64d67083e61..12d78bac5df 100644 --- a/tests/baselines/reference/generatorTypeCheck63.types +++ b/tests/baselines/reference/generatorTypeCheck63.types @@ -12,7 +12,7 @@ export function strategy(stratName: string, gen: (a: T >a : T return function*(state) { ->function*(state) { for (const next of gen(state)) { if (next) { next.lastStrategyApplied = stratName; } yield next; } } : (state: T) => Generator +>function*(state) { for (const next of gen(state)) { if (next) { next.lastStrategyApplied = stratName; } yield next; } } : (state: T) => Generator >state : T for (const next of gen(state)) { @@ -53,7 +53,7 @@ export const Nothing: Strategy = strategy("Nothing", function* (state: St >strategy("Nothing", function* (state: State) { yield 1; return state;}) : any >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function* (state: State) { yield 1; return state;} : (state: State) => Generator +>function* (state: State) { yield 1; return state;} : (state: State) => Generator >state : State yield 1; @@ -70,7 +70,7 @@ export const Nothing1: Strategy = strategy("Nothing", function* (state: S >strategy("Nothing", function* (state: State) {}) : (a: State) => IterableIterator >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function* (state: State) {} : (state: State) => Generator +>function* (state: State) {} : (state: State) => Generator >state : State }); @@ -80,7 +80,7 @@ export const Nothing2: Strategy = strategy("Nothing", function* (state: S >strategy("Nothing", function* (state: State) { return 1;}) : (a: State) => IterableIterator >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function* (state: State) { return 1;} : (state: State) => Generator +>function* (state: State) { return 1;} : (state: State) => Generator >state : State return 1; @@ -93,7 +93,7 @@ export const Nothing3: Strategy = strategy("Nothing", function* (state: S >strategy("Nothing", function* (state: State) { yield state; return 1;}) : (a: State) => IterableIterator >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function* (state: State) { yield state; return 1;} : (state: State) => Generator +>function* (state: State) { yield state; return 1;} : (state: State) => Generator >state : State yield state; diff --git a/tests/baselines/reference/generatorYieldContextualType.types b/tests/baselines/reference/generatorYieldContextualType.types index 5caccffa933..a90bbd040a1 100644 --- a/tests/baselines/reference/generatorYieldContextualType.types +++ b/tests/baselines/reference/generatorYieldContextualType.types @@ -6,7 +6,7 @@ declare function f1(gen: () => Generator): void; f1<0, 0, 1>(function* () { >f1<0, 0, 1>(function* () { const a = yield 0; return 0;}) : void >f1 : (gen: () => Generator) => void ->function* () { const a = yield 0; return 0;} : () => Generator<0, 0, unknown> +>function* () { const a = yield 0; return 0;} : () => Generator<0, 0, 1> const a = yield 0; >a : 1 @@ -25,7 +25,7 @@ declare function f2(gen: () => Generator | AsyncGenerator(async function* () { >f2<0, 0, 1>(async function* () { const a = yield 0; return 0;}) : void >f2 : (gen: () => Generator | AsyncGenerator) => void ->async function* () { const a = yield 0; return 0;} : () => AsyncGenerator<0, 0, unknown> +>async function* () { const a = yield 0; return 0;} : () => AsyncGenerator<0, 0, 1> const a = yield 0; >a : 1 diff --git a/tests/baselines/reference/types.asyncGenerators.es2018.1.types b/tests/baselines/reference/types.asyncGenerators.es2018.1.types index 24da9312c15..54db9b890ec 100644 --- a/tests/baselines/reference/types.asyncGenerators.es2018.1.types +++ b/tests/baselines/reference/types.asyncGenerators.es2018.1.types @@ -75,7 +75,7 @@ async function * inferReturnType8() { } const assignability1: () => AsyncIterableIterator = async function * () { >assignability1 : () => AsyncIterableIterator ->async function * () { yield 1;} : () => AsyncGenerator +>async function * () { yield 1;} : () => AsyncGenerator yield 1; >yield 1 : undefined @@ -84,7 +84,7 @@ const assignability1: () => AsyncIterableIterator = async function * () }; const assignability2: () => AsyncIterableIterator = async function * () { >assignability2 : () => AsyncIterableIterator ->async function * () { yield Promise.resolve(1);} : () => AsyncGenerator +>async function * () { yield Promise.resolve(1);} : () => AsyncGenerator yield Promise.resolve(1); >yield Promise.resolve(1) : undefined @@ -135,7 +135,7 @@ const assignability5: () => AsyncIterableIterator = async function * () }; const assignability6: () => AsyncIterable = async function * () { >assignability6 : () => AsyncIterable ->async function * () { yield 1;} : () => AsyncGenerator +>async function * () { yield 1;} : () => AsyncGenerator yield 1; >yield 1 : undefined @@ -144,7 +144,7 @@ const assignability6: () => AsyncIterable = async function * () { }; const assignability7: () => AsyncIterable = async function * () { >assignability7 : () => AsyncIterable ->async function * () { yield Promise.resolve(1);} : () => AsyncGenerator +>async function * () { yield Promise.resolve(1);} : () => AsyncGenerator yield Promise.resolve(1); >yield Promise.resolve(1) : undefined @@ -195,7 +195,7 @@ const assignability10: () => AsyncIterable = async function * () { }; const assignability11: () => AsyncIterator = async function * () { >assignability11 : () => AsyncIterator ->async function * () { yield 1;} : () => AsyncGenerator +>async function * () { yield 1;} : () => AsyncGenerator yield 1; >yield 1 : undefined @@ -204,7 +204,7 @@ const assignability11: () => AsyncIterator = async function * () { }; const assignability12: () => AsyncIterator = async function * () { >assignability12 : () => AsyncIterator ->async function * () { yield Promise.resolve(1);} : () => AsyncGenerator +>async function * () { yield Promise.resolve(1);} : () => AsyncGenerator yield Promise.resolve(1); >yield Promise.resolve(1) : undefined diff --git a/tests/baselines/reference/types.asyncGenerators.es2018.2.errors.txt b/tests/baselines/reference/types.asyncGenerators.es2018.2.errors.txt index 1ca77aebc86..d7ec011bced 100644 --- a/tests/baselines/reference/types.asyncGenerators.es2018.2.errors.txt +++ b/tests/baselines/reference/types.asyncGenerators.es2018.2.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(2,12): error TS2504: Type '{}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(8,12): error TS2504: Type 'Promise' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(10,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. - Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(10,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. + Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. Types of property 'next' are incompatible. - Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. + Type '(...args: [] | [PromiseLike]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. Type 'Promise>' is not assignable to type 'Promise>'. Type 'IteratorResult' is not assignable to type 'IteratorResult'. Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. @@ -11,20 +11,12 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts( Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(13,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. - Types of property 'next' are incompatible. - Type '(...args: [] | [PromiseLike]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. - Type 'Promise>' is not assignable to type 'Promise>'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(16,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(19,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. - Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. - Types of property '[Symbol.asyncIterator]' are incompatible. - Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. - Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. - Types of property 'next' are incompatible. - Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. - Type 'Promise>' is not assignable to type 'Promise>'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(22,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. + Types of property 'next' are incompatible. + Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. + Type 'Promise>' is not assignable to type 'Promise>'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(19,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. Types of property '[Symbol.asyncIterator]' are incompatible. Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. @@ -32,10 +24,18 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts( Types of property 'next' are incompatible. Type '(...args: [] | [PromiseLike]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. Type 'Promise>' is not assignable to type 'Promise>'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(22,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. + Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(25,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(28,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. - Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. + Types of property '[Symbol.asyncIterator]' are incompatible. + Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. + Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. + Types of property 'next' are incompatible. + Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. + Type 'Promise>' is not assignable to type 'Promise>'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(28,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. + Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(31,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(34,7): error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. @@ -76,10 +76,10 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts( } const assignability1: () => AsyncIterableIterator = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. -!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. +!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. +!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. !!! error TS2322: Types of property 'next' are incompatible. -!!! error TS2322: Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. +!!! error TS2322: Type '(...args: [] | [PromiseLike]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. !!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. !!! error TS2322: Type 'IteratorResult' is not assignable to type 'IteratorResult'. !!! error TS2322: Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. @@ -91,31 +91,19 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts( ~~~~~~~~~~~~~~ !!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. !!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. -!!! error TS2322: Types of property 'next' are incompatible. -!!! error TS2322: Type '(...args: [] | [PromiseLike]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. -!!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. yield* ["a", "b"]; }; const assignability3: () => AsyncIterableIterator = async function * () { ~~~~~~~~~~~~~~ !!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterableIterator'. !!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterableIterator'. +!!! error TS2322: Types of property 'next' are incompatible. +!!! error TS2322: Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. +!!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. yield* (async function * () { yield "a"; })(); }; const assignability4: () => AsyncIterable = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. -!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. -!!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible. -!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. -!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. -!!! error TS2322: Types of property 'next' are incompatible. -!!! error TS2322: Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. -!!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. - yield "a"; - }; - const assignability5: () => AsyncIterable = async function * () { - ~~~~~~~~~~~~~~ !!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. !!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. !!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible. @@ -124,18 +112,30 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts( !!! error TS2322: Types of property 'next' are incompatible. !!! error TS2322: Type '(...args: [] | [PromiseLike]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. !!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. + yield "a"; + }; + const assignability5: () => AsyncIterable = async function * () { + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. +!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. yield* ["a", "b"]; }; const assignability6: () => AsyncIterable = async function * () { ~~~~~~~~~~~~~~ !!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterable'. !!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterable'. +!!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible. +!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. +!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. +!!! error TS2322: Types of property 'next' are incompatible. +!!! error TS2322: Type '(...args: [] | [unknown]) => Promise>' is not assignable to type '(...args: [] | [PromiseLike]) => Promise>'. +!!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. yield* (async function * () { yield "a"; })(); }; const assignability7: () => AsyncIterator = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. -!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. +!!! error TS2322: Type '() => AsyncGenerator' is not assignable to type '() => AsyncIterator'. +!!! error TS2322: Type 'AsyncGenerator' is not assignable to type 'AsyncIterator'. yield "a"; }; const assignability8: () => AsyncIterator = async function * () { diff --git a/tests/baselines/reference/types.asyncGenerators.es2018.2.types b/tests/baselines/reference/types.asyncGenerators.es2018.2.types index 022ddd297a2..83524871199 100644 --- a/tests/baselines/reference/types.asyncGenerators.es2018.2.types +++ b/tests/baselines/reference/types.asyncGenerators.es2018.2.types @@ -29,7 +29,7 @@ async function * inferReturnType3() { } const assignability1: () => AsyncIterableIterator = async function * () { >assignability1 : () => AsyncIterableIterator ->async function * () { yield "a";} : () => AsyncGenerator +>async function * () { yield "a";} : () => AsyncGenerator yield "a"; >yield "a" : undefined @@ -62,7 +62,7 @@ const assignability3: () => AsyncIterableIterator = async function * () }; const assignability4: () => AsyncIterable = async function * () { >assignability4 : () => AsyncIterable ->async function * () { yield "a";} : () => AsyncGenerator +>async function * () { yield "a";} : () => AsyncGenerator yield "a"; >yield "a" : undefined @@ -95,7 +95,7 @@ const assignability6: () => AsyncIterable = async function * () { }; const assignability7: () => AsyncIterator = async function * () { >assignability7 : () => AsyncIterator ->async function * () { yield "a";} : () => AsyncGenerator +>async function * () { yield "a";} : () => AsyncGenerator yield "a"; >yield "a" : undefined diff --git a/tests/baselines/reference/uniqueSymbols.types b/tests/baselines/reference/uniqueSymbols.types index 02ededf7b1f..a321593c11a 100644 --- a/tests/baselines/reference/uniqueSymbols.types +++ b/tests/baselines/reference/uniqueSymbols.types @@ -819,7 +819,7 @@ interface Context { const o3: Context = { >o3 : Context ->{ method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; },} : { method1(): unique symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): unique symbol; } +>{ method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; },} : { method1(): unique symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): unique symbol; } method1() { >method1 : () => unique symbol @@ -836,7 +836,7 @@ const o3: Context = { }, async * method3() { ->method3 : () => AsyncGenerator +>method3 : () => AsyncGenerator yield s; // yield type should not widen due to contextual type >yield s : undefined @@ -844,7 +844,7 @@ const o3: Context = { }, * method4() { ->method4 : () => Generator +>method4 : () => Generator yield s; // yield type should not widen due to contextual type >yield s : undefined diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.types b/tests/baselines/reference/uniqueSymbolsDeclarations.types index db198153153..bacdafc5680 100644 --- a/tests/baselines/reference/uniqueSymbolsDeclarations.types +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.types @@ -812,7 +812,7 @@ interface Context { const o4: Context = { >o4 : Context ->{ method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; }} : { method1(): unique symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): unique symbol; } +>{ method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; }} : { method1(): unique symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): unique symbol; } method1() { >method1 : () => unique symbol @@ -829,7 +829,7 @@ const o4: Context = { }, async * method3() { ->method3 : () => AsyncGenerator +>method3 : () => AsyncGenerator yield s; // yield type should not widen due to contextual type >yield s : undefined @@ -837,7 +837,7 @@ const o4: Context = { }, * method4() { ->method4 : () => Generator +>method4 : () => Generator yield s; // yield type should not widen due to contextual type >yield s : undefined