Skip to content

Error with async generators #32247

Closed
@falsandtru

Description

@falsandtru

@rbuckton

TypeScript Version: master

Search Terms:

Code

const g: <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>) => Promise<U> = async <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>): Promise<U> => {
  throw com;
};

Expected behavior:
pass
Actual behavior:

index.ts:1:7 - error TS2719: Type '<U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>) => Promise<U>' is not assignable to type '<U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>) => Promise<U>'. Two different types with this name exist, but they are unrelated.
  Type 'Promise<U | PromiseLike<U>>' is not assignable to type 'Promise<U>'.
    Type 'U | PromiseLike<U>' is not assignable to type 'U'.
      'U | PromiseLike<U>' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'.
        Type 'PromiseLike<U>' is not assignable to type 'U'.
          'PromiseLike<U>' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'.

1 const g: <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>) => Promise<U> = async <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>): Promise<U> => {
        ~

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions