Skip to content
Open
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
4 changes: 3 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20962,7 +20962,9 @@ func (c *Checker) checkAndAggregateYieldOperandTypes(fn *ast.Node, checkMode Che
if yieldExpr.Expression() != nil && c.isConstContext(yieldExpr.Expression()) {
yieldExprType = c.getRegularTypeOfLiteralType(yieldExprType)
}
yieldTypes = core.AppendIfUnique(yieldTypes, c.getYieldedTypeOfYieldExpression(yieldExpr, yieldExprType, c.anyType, isAsync))
if yieldedType := c.getYieldedTypeOfYieldExpression(yieldExpr, yieldExprType, c.anyType, isAsync); yieldedType != nil {
yieldTypes = core.AppendIfUnique(yieldTypes, yieldedType)
}
var nextType *Type
if yieldExpr.AsYieldExpression().AsteriskToken != nil {
iterationTypes := c.getIterationTypesOfIterable(yieldExprType, core.IfElse(isAsync, IterationUseAsyncYieldStar, IterationUseYieldStar), yieldExpr.Expression())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
asyncGeneratorInvalidThenable.ts(3,11): error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
asyncGeneratorInvalidThenable.ts(9,11): error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
asyncGeneratorInvalidThenable.ts(13,11): error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
asyncGeneratorInvalidThenable.ts(19,11): error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
asyncGeneratorInvalidThenable.ts(20,11): error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
asyncGeneratorInvalidThenable.ts(24,11): error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
asyncGeneratorInvalidThenable.ts(28,33): error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.


==== asyncGeneratorInvalidThenable.ts (7 errors) ====
// https://github.com/microsoft/TypeScript/issues/65378
async function* invalidThenableBeforeValue() {
yield { then() {} };
~~~~~~~~~~~~~
!!! error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
yield 1;
}

async function* invalidThenableAfterValue() {
yield 1;
yield { then() {} };
~~~~~~~~~~~~~
!!! error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
}

async function* invalidThenableWithMultipleValues() {
yield { then() {} };
~~~~~~~~~~~~~
!!! error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
yield 1;
yield "text";
}

async function* onlyInvalidThenables() {
yield { then() {} };
~~~~~~~~~~~~~
!!! error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
yield { then() {} };
~~~~~~~~~~~~~
!!! error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
}

async function* singleInvalidThenable() {
yield { then() {} };
~~~~~~~~~~~~~
!!! error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
}

async function* invalidThenableWithNext() {
const next: boolean = yield { then() {} };
~~~~~~~~~~~~~
!!! error TS1321: Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.
yield 1;
return next;
}

async function* validYields() {
yield Promise.resolve(1);
yield "text";
}

function* synchronousThenable() {
yield { then() {} };
yield 1;
}

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

=== asyncGeneratorInvalidThenable.ts ===
// https://github.com/microsoft/TypeScript/issues/65378
async function* invalidThenableBeforeValue() {
>invalidThenableBeforeValue : Symbol(invalidThenableBeforeValue, Decl(asyncGeneratorInvalidThenable.ts, 0, 0))

yield { then() {} };
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 2, 11))

yield 1;
}

async function* invalidThenableAfterValue() {
>invalidThenableAfterValue : Symbol(invalidThenableAfterValue, Decl(asyncGeneratorInvalidThenable.ts, 4, 1))

yield 1;
yield { then() {} };
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 8, 11))
}

async function* invalidThenableWithMultipleValues() {
>invalidThenableWithMultipleValues : Symbol(invalidThenableWithMultipleValues, Decl(asyncGeneratorInvalidThenable.ts, 9, 1))

yield { then() {} };
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 12, 11))

yield 1;
yield "text";
}

async function* onlyInvalidThenables() {
>onlyInvalidThenables : Symbol(onlyInvalidThenables, Decl(asyncGeneratorInvalidThenable.ts, 15, 1))

yield { then() {} };
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 18, 11))

yield { then() {} };
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 19, 11))
}

async function* singleInvalidThenable() {
>singleInvalidThenable : Symbol(singleInvalidThenable, Decl(asyncGeneratorInvalidThenable.ts, 20, 1))

yield { then() {} };
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 23, 11))
}

async function* invalidThenableWithNext() {
>invalidThenableWithNext : Symbol(invalidThenableWithNext, Decl(asyncGeneratorInvalidThenable.ts, 24, 1))

const next: boolean = yield { then() {} };
>next : Symbol(next, Decl(asyncGeneratorInvalidThenable.ts, 27, 9))
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 27, 33))

yield 1;
return next;
>next : Symbol(next, Decl(asyncGeneratorInvalidThenable.ts, 27, 9))
}

async function* validYields() {
>validYields : Symbol(validYields, Decl(asyncGeneratorInvalidThenable.ts, 30, 1))

yield Promise.resolve(1);
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))

yield "text";
}

function* synchronousThenable() {
>synchronousThenable : Symbol(synchronousThenable, Decl(asyncGeneratorInvalidThenable.ts, 35, 1))

yield { then() {} };
>then : Symbol(then, Decl(asyncGeneratorInvalidThenable.ts, 38, 11))

yield 1;
}

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

=== asyncGeneratorInvalidThenable.ts ===
// https://github.com/microsoft/TypeScript/issues/65378
async function* invalidThenableBeforeValue() {
>invalidThenableBeforeValue : () => AsyncGenerator<number, void, unknown>

yield { then() {} };
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void

yield 1;
>yield 1 : any
>1 : 1
}

async function* invalidThenableAfterValue() {
>invalidThenableAfterValue : () => AsyncGenerator<number, void, unknown>

yield 1;
>yield 1 : any
>1 : 1

yield { then() {} };
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void
}

async function* invalidThenableWithMultipleValues() {
>invalidThenableWithMultipleValues : () => AsyncGenerator<"text" | 1, void, unknown>

yield { then() {} };
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void

yield 1;
>yield 1 : any
>1 : 1

yield "text";
>yield "text" : any
>"text" : "text"
}

async function* onlyInvalidThenables() {
>onlyInvalidThenables : () => AsyncGenerator<never, void, unknown>

yield { then() {} };
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void

yield { then() {} };
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void
}

async function* singleInvalidThenable() {
>singleInvalidThenable : () => AsyncGenerator<never, void, unknown>

yield { then() {} };
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void
}

async function* invalidThenableWithNext() {
>invalidThenableWithNext : () => AsyncGenerator<number, boolean, boolean>

const next: boolean = yield { then() {} };
>next : boolean
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void

yield 1;
>yield 1 : any
>1 : 1

return next;
>next : boolean
}

async function* validYields() {
>validYields : () => AsyncGenerator<number | "text", void, unknown>

yield Promise.resolve(1);
>yield Promise.resolve(1) : any
>Promise.resolve(1) : Promise<number>
>Promise.resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; }
>Promise : PromiseConstructor
>resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; }
>1 : 1

yield "text";
>yield "text" : any
>"text" : "text"
}

function* synchronousThenable() {
>synchronousThenable : () => Generator<1 | { then(): void; }, void, unknown>

yield { then() {} };
>yield { then() {} } : any
>{ then() {} } : { then(): void; }
>then : () => void

yield 1;
>yield 1 : any
>1 : 1
}

45 changes: 45 additions & 0 deletions tsc/testdata/tests/cases/compiler/asyncGeneratorInvalidThenable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @target: es2020
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/65378
async function* invalidThenableBeforeValue() {
yield { then() {} };
yield 1;
}

async function* invalidThenableAfterValue() {
yield 1;
yield { then() {} };
}

async function* invalidThenableWithMultipleValues() {
yield { then() {} };
yield 1;
yield "text";
}

async function* onlyInvalidThenables() {
yield { then() {} };
yield { then() {} };
}

async function* singleInvalidThenable() {
yield { then() {} };
}

async function* invalidThenableWithNext() {
const next: boolean = yield { then() {} };
yield 1;
return next;
}

async function* validYields() {
yield Promise.resolve(1);
yield "text";
}

function* synchronousThenable() {
yield { then() {} };
yield 1;
}