Skip to content

Generator<T>/AsyncGenerator<T> type references reject the lib's optional TReturn/TNext (arity fixed at 1) #487

@nickna

Description

@nickna

Found while implementing #456. The Iterator/IterableIterator arm added there accepts the lib's defaulted type-parameter range (Iterator<T, TReturn = any, TNext = any>, 1–3 args). The pre-existing Generator / AsyncGenerator arms in ResolveGenericType (TypeChecker.Generics.cs) still require exactly 1 type argument, so they reject the lib spelling.

Repro

function* gen(): Generator<number, void, unknown> { yield 1; }
//                ^ Type Error:  Generator requires exactly 1 type argument, got 3.

The lib signatures are Generator<T = unknown, TReturn = any, TNext = unknown> and AsyncGenerator<T = unknown, TReturn = any, TNext = unknown>.

Fix shape

In ResolveGenericType, change the Generator / AsyncGenerator arms to accept 1–3 arguments and keep only the first (the yield type), dropping TReturn/TNext — exactly like the Iterator / IterableIterator arm added in #456. Out-of-range should be TS2707 ("requires between 1 and 3 type arguments"), the code tsc uses for a defaulted range, matching the Iterator arm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions