Skip to content

es-get-iterator broken by IIFE now allowing contextual return type  #45559

Closed
@sandersn

Description

@sandersn

Broken by #45007:

interface Iterable<T, TReturn = unknown, TNext = undefined> {
    [Symbol.iterator](): Iterator<T, TReturn, TNext>;
}

type InferIterable<T> = T extends Iterable<infer TYield, infer TReturn, infer TNext>
    ? Iterator<TYield, TReturn, TNext>
    : unknown extends T
        ? Iterator<unknown> | undefined
        : undefined;

declare function getIterator<T>(iterable: T): InferIterable<T>;

var x = getIterator((function*() { yield "foo"; yield "bar"; })());

Expected: x: Iterator<"foo" | "bar", void, unknown>

Actual: x: Iterator<"foo" | "bar", void, any>

I think this is an acceptable break, but I want another round of thinking about it now that we have a concrete example.

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing code

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions