GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve type checking and inference for Generators and Async Generators by rbuckton · Pull Request #30790 · microsoft/TypeScript

Conversation

@rbuckton

@rbuckton Ron Buckton (rbuckton) commented Apr 6, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR changes the definitions for IteratorResult, Generator, and AsyncGenerator and makes a number of improvements in how we check and infer types for yield and return inside of the body of a generator or async generator.

Type Definition Changes:

// es2015.iterable.d.ts
interface IteratorYieldResult<TYield> {
    done: false;
    value: TYield;
}

interface IteratorReturnResult<TReturn> {
    done: true;
    value: TReturn;
}

type IteratorResult<T, TReturn = any> = 
    | IteratorYieldResult<T>
    | IteratorReturnResult<TReturn>;

interface Iterator<T, TReturn = any, TNext = undefined> {
    // NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors
    // in all places.
    next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
    return?(value?: TReturn): IteratorResult<T, TReturn>;
    throw?(e?: any): IteratorResult<T, TReturn>;
}

// es2015.generator.d.ts
interface Generator<T = unknown, TReturn = any, TNext = unknown> 
    extends Iterator<T, TReturn, TNext> {
    // NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors
    // in all places.
    next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
    return(value: TReturn): IteratorResult<T, TReturn>;
    throw(e: any): IteratorResult<T, TReturn>;
    [Symbol.iterator](): Generator<T, TReturn, TNext>;
}

// es2018.asynciterable.d.ts
interface AsyncIterator<T, TReturn = any, TNext = undefined> {
    // NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors
    // in all places.
    next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
    return?(value?: TReturn): Promise<IteratorResult<T, TReturn>>;
    throw?(e?: any): Promise<IteratorResult<T, TReturn>>;
}

// es2018.asyncgenerator.d.ts
interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> 
    extends AsyncIterator<T, TReturn, TNext> {
    // NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors
    // in all places.
    next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
    return(value: TReturn): Promise<IteratorResult<T, TReturn>>;
    throw(e: any): Promise<IteratorResult<T, TReturn>>;
    [Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>;
}

Type Checker Changes

With these new definitions, a generator can now distinguish between the following three types:

  • yielded type - The type of the expression provided to yield (i.e. TYield above)
  • returned type - The type of the expression provided to return (i.e. TReturn above)
  • next type - The type of the value accepted in a call to next() on the generator (i.e. TNext above).

Inside of the type checker we have also made the following changes to improve checking and inference when inside the body of a generator or async generator:

  • In a generator with an explicit return type annotation:
    • We will now correctly check the expression provided to return against the returned type of the generator's return type annotation (i.e. the TReturn type in the Generator definition above).
    • We will now correctly check, and provide a type for, the result of a yield expression based on the next type of the generator's return type annotation (i.e. the TNext type in the Generator definition above).
  • When inferring the return type of a generator without a return type annotation:
    • We will now infer the yielded type and return type as separate types rather than using a union of both types.
    • We will infer the next type as an intersection of the contextual types of each yield expression.
    • We no longer treat function*f(){} as an implicit-any error, and will instead give it a return type of Generator<never, void, unknown>. This aligns with our behavior for function f(){} where we infer a return type of void.

Here are several examples of the new behavior:

function* f(): Generator</*TYield*/ number, /*TReturn*/ string, /*TNext*/ number> {
  const x = yield 1; // ok, '1' is assignable to 'number'
  x; // 'x' has type 'number'

  const y: string = yield 2; // error, 'number' (the type of TNext) is not assignable to 'string'

  return ""; // ok, '""' is assignable to 'string'
}

function* g() {
  let i = 1;
  let s = "";
  // NOTE: for 'TNext' we will infer the intersection of A & B as that is the only type that
  // satisfies *both* assignments.
  const a: A = yield i;
  const b: B = yield s;
  return true;
}

g; // 'g' has type '() => Generator<string | number, boolean, A & B>'

Notes

  • For these definitions TReturn has a default of any. This is necessary for backwards compatibility when assigning a { done: boolean, value: number } type to an IteratorResult<number>, which is often the case when the source type is result of widening an object literal's type when there is no contextual type.
  • For existing code using weakly-typed iterators (i.e. { next(): { done: boolean, value: T } }) to still be considered asssignable, this PR depends on Relate source types covered by a target discriminated union #30779 (Relate source types covered by a target discriminated union).
    • NOTE: Relate source types covered by a target discriminated union #30779 has been merged.

Fixes #13847 (types will be checked correctly if return type is specified as Generator<T, void>)
Fixes #26959
Fixes #2983
Fixes #21527
Fixes #31214

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kingwl, raveclassic, Jomik, haltman-at, trotyl, gnidan, TylorS, jaredklewis, sam-goodwin, jonaskello, and 38 more reacted with thumbs up emoji Kingwl, raveclassic, Jomik, MattiasBuelens, trotyl, gnidan, TylorS, jaredklewis, sam-goodwin, jonaskello, and 21 more reacted with hooray emoji Kingwl, raveclassic, Jomik, trotyl, gnidan, TylorS, jaredklewis, sam-goodwin, jonaskello, Igorbek, and 12 more reacted with heart emoji Kingwl, raveclassic, Jomik, TylorS, jaredklewis, sam-goodwin, jonaskello, trotyl, Igorbek, kasperpeulen, and 8 more reacted with rocket emoji
All reactions
  • 👍 48 reactions
  • 🎉 31 reactions
  • ❤️ 22 reactions
  • 🚀 18 reactions
@rbuckton Ron Buckton (rbuckton) mentioned this pull request Apr 6, 2019
Warning when writing a generator function without any yield #13847
Closed
@rbuckton
Ron Buckton (rbuckton) requested review from Daniel Rosenwasser (DanielRosenwasser), Ryan Cavanaugh (RyanCavanaugh), Anders Hejlsberg (ahejlsberg) and Wesley Wigham (weswigham) April 6, 2019 01:28
@rbuckton

Ron Buckton (rbuckton) commented Apr 6, 2019

Copy link
Copy Markdown
Contributor Author

TypeScript Bot (@typescript-bot) test this
TypeScript Bot (@typescript-bot) run dt

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Apr 6, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the Definitely Typed test suite on this PR at 03afdb4. You can monitor the build here. It should now contribute to this PR's status checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Apr 6, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the extended test suite on this PR at 03afdb4. You can monitor the build here. It should now contribute to this PR's status checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yortus

Troy Gerwien (yortus) commented Apr 6, 2019

Copy link
Copy Markdown
Contributor

It's great that yield and return types are now treated separately.

However it looks like the typing for yield/next types won't be able to model uses like co (I described that use-case a bit in #2983). However I don't know if anyone still uses that library or indeed how people use generators these days. Just curious what kind of usage patterns you came across in deciding to do it this way.

If there are still co-style usecases out there (i.e. where the type of each yield expression is a function of that yield's operand, and unrelated to the other yields), what will they have to do to pass these new type-checking rules? Explicit casts?

treybrisbane, paldepind, matthargett, dfreeman, and raveclassic reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Apr 6, 2019

Copy link
Copy Markdown
Contributor Author

Unfortunately, casts would be necessary. The problems is that you would need a way to relate the yielded type to the next type:

function* f(): /* some type to relate 'y' to 'x' */ {
  let x = yield y;
}

Our compiler does not currently have a mechanism to handle this scenario.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yortus

Troy Gerwien (yortus) commented Apr 6, 2019

Copy link
Copy Markdown
Contributor

Well a type-level function from the yielded type to the next type would be simple enough to express in TypeScript. It's just a generic type. For co it would be something like:

type Next<TYielded> =
    TYielded extends Promise<infer U> ? U :
    TYielded extends Array<Promise<infer U>> ? U[] :
    TYielded;

But the type function itself would need be to be passed as a type parameter to Generator<>, which I guess is the bit that tsc currently doesn't support.

treybrisbane and brandonburrus reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xaviergonz

Javier Gonzalez (xaviergonz) commented Apr 6, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Just curious, will this proposal support emulating async/await?
This is, something like

// yields must be done over promises
asAsyncAwaitish(
  function* g(target: number) { // function generator works similar to async
    const a = yield Promise.resolve(3); // a is number (3?), similar to await
    const b = yield Promise.resolve("hi") // b is string ("hi"?), similar to await
    return a === target; // final returned type is a boolean
  }
) // typed as (target: number) => Promise<boolean>

if so, what would the Generator type look like?

Basically I'm just wondering if properly typing flows from mobx (https://mobx.js.org/best/actions.html - flow section) would be possible after this is in.

akphi, benny-eu, and evelant reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Apr 7, 2019

Copy link
Copy Markdown
Contributor Author

Javier Gonzalez (@xaviergonz): That is essentially what Troy Gerwien (@yortus) was discussing earlier. No, that is not supported at this time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@treybrisbane

Trey Brisbane (treybrisbane) commented Apr 7, 2019

Copy link
Copy Markdown

+1 for the usecase Troy Gerwien (@yortus) mentioned (in my case, it's more around monadic operations as mentioned here, but effectively the same thing).

Even without that, this PR will be a huge improvement to generator support, and I'm glad to see them getting some love! :D

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Apr 7, 2019

Copy link
Copy Markdown
Contributor Author

Troy Gerwien (@yortus): Yes, we would probably need some mechanism for higher-order generics which would allow us to do something like this:

interface InteractiveGenerator<TNext<TYield>, TReturn> {
    next(value?: TNext): IteratorResult<TYield, TReturn>;
    return(value: TReturn): IteratorResult<TYield, TReturn>;
    throw(err: any): IteratorResult<TYield, TReturn>;
}

type Await<T> = T extends PromiseLike<infer U> ? U : T;

function* f(): InteractiveGenerator<Await, void> {
  const x = yield Promise.resolve(1);
  // TYield: 'Promise<number>'
  // TNext: 'Await<TYield>' -> 'Await<Promise<number>>' -> 'number'
  // x: 'number'
}

If we do add a feature for higher-order generics in the future, I imagine this would be feasible to implement over a separate interface like InteractiveGenerator above. However, that is out of scope for this PR.

treybrisbane, yortus, EvanCahill, soerenBoisen, raveclassic, kgtkr, reiv, evelant, btmills, chbdetta, and 2 more reacted with thumbs up emoji
All reactions
  • 👍 12 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton
Ron Buckton (rbuckton) force-pushed the strictGeneratorTypes branch 2 times, most recently from 0e23eac to 8204898 Compare April 7, 2019 05:38
@rbuckton

Ron Buckton (rbuckton) commented Apr 7, 2019

Copy link
Copy Markdown
Contributor Author

TypeScript Bot (@typescript-bot) test this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Apr 7, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the extended test suite on this PR at 8204898. You can monitor the build here. It should now contribute to this PR's status checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yortus

Troy Gerwien (yortus) commented Apr 7, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I just remembered #1213, which tracks higher-order generics. So if that issue was resolved, then usecases like co, mobx, and redux-saga could be fully typed (in some other PR in the future obviously).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Apr 7, 2019

Copy link
Copy Markdown
Contributor Author

Looks like the RWC errors fall into two categories:

  • Conflicts with IteratorResult due to the older version of node definitions used in the RWC tests.
  • A missing definition for Generator since it is defined in es2015.generator and not es2015.iterable.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Apr 7, 2019

Copy link
Copy Markdown
Contributor Author

TypeScript Bot (@typescript-bot) run dt

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Apr 7, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I've started to run the Definitely Typed test suite on this PR at 8204898. You can monitor the build here. It should now contribute to this PR's status checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Apr 7, 2019

Copy link
Copy Markdown
Contributor Author

DT Failures fall into one of three categories:

  • Tests that don't distinguish between done: true and done: false in IteratorResult (adone, ckeditor).
  • An assignment compatibility error in the tests for 'co'.
  • Identifier collisions for IteratorResult in node v7, v8, and v9.

The tests for 'adone' and 'ckeditor' can be easily fixed though I need to take a closer look at the 'co' tests. The errors in Node were expected, and we've already addressed them using <reference lib= entries for Node v10 and v11, so we would likely need to make the same change in the earlier node library versions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@paldepind

Simon Friis Vindum (paldepind) commented Apr 8, 2019

Copy link
Copy Markdown

Troy Gerwien (@yortus)

However it looks like the typing for yield/next types won't be able to model uses like co (I described that use-case a bit in #2983). However I don't know if anyone still uses that library or indeed how people use generators these days.

redux-saga is a very popular library that uses generators in a way similar to co and which would benefit from what you're describing.

yortus, treybrisbane, gnidan, sam-goodwin, martynaskadisa, echenley, Andarist, raveclassic, djonin, GGwujun, and 3 more reacted with thumbs up emoji
All reactions
  • 👍 13 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Igorbek

Igor Oleinikov (Igorbek) commented Apr 9, 2019

Copy link
Copy Markdown
Contributor

This will be a great addition!
I have a few questions,

  • why does Generator's throw accept e: any but AsyncGenerator's one accepts e: unknown?
  • next accepts optional parameter, but yeild's result (next) doesn't contain | undefined implicitly, right?
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MattiasBuelens

Mattias Buelens (MattiasBuelens) commented Apr 9, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • why does Generator's throw accept e: any but AsyncGenerator's one accepts e: unknown?

throw(e: unknown) seems like a better choice than throw(e: any). With unknown, the AsyncGenerator implementation must narrow the type of e before it can use it (e.g. using instanceof Error or a type guard).

I assume Generator must have throw(e: any) because changing it to unknown would break backwards compatibility (not an expert on this, so correct me if I'm wrong! 😉). Since AsyncGenerator is a new interface, TypeScript can use the more appropriate unknown type instead.

  • next accepts optional parameter, but yield's result (next) doesn't contain | undefined implicitly, right?

Correct.

This is because the (async) generator only starts executing after the first next() call (see MDN). As such, the argument to the first next() call will be ignored by the (async) generator. However, for all future next() calls, you should pass an argument to next().

There's no way to encode this behavior at the type level. To know whether value is optional or not, the type checker would need to know whether next() has been called before, but that's very hard (if not impossible) to know at compile time. Therefore, marking value as always optional is an approximation: it does not give false negatives (for programs that do not pass a value to the first next() call), but it can give false positives (for programs that do not pass a value to subsequent next() calls).

TNext does not need to include undefined. If you use the generator correctly (and TypeScript assumes you do), then you'll always pass a value of type TNext to all next() calls (except for the first call).

whzx5byb reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@haltman-at Harry Altman (haltman-at) mentioned this pull request Apr 10, 2019
Move from promise-based decoder that makes web3 calls to generator-based decoder that makes requests to caller ConsenSys-archive/truffle#1900
Merged
@rbuckton Ron Buckton (rbuckton) mentioned this pull request Apr 12, 2019
[NodeJS] Support 'typesVersions' in node/v6 through node/v9 DefinitelyTyped/DefinitelyTyped#34678
Merged
@raveclassic Kirill Agalakov (raveclassic) mentioned this pull request Apr 12, 2019
Start working on v2 gcanti/fp-ts#823
Closed
@rbuckton

Ron Buckton (rbuckton) commented Jul 4, 2019

Copy link
Copy Markdown
Contributor Author

We already addressed this issue in @types/[email protected] with the addition of a "typesVersions" entry in the package.json.

buschtoens, ExE-Boss, and davelsio reacted with heart emoji
All reactions
  • ❤️ 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Jan Buschtöns (buschtoens) added a commit to ember-decorators/ember-decorators that referenced this pull request Jul 4, 2019
@buschtoens
fix(deps): upgrade @types/node@^9.6.48
d2f8b57
microsoft/TypeScript#30790 (comment)
@buschtoens

Jan Buschtöns (buschtoens) commented Jul 4, 2019

Copy link
Copy Markdown

Ron Buckton (@rbuckton) Awesome! Thank you so much — That fixed it! You just saved me hours of research. ❤

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton Ron Buckton (rbuckton) mentioned this pull request Jul 5, 2019
🤖 User test baselines have changed #32267
Closed
@gilbsgilbs Gilbert Gilb's (gilbsgilbs) mentioned this pull request Jul 7, 2019
Documentation/Recipe Request: Using redux-saga with TypeScript redux-saga/redux-saga#1286
Closed
@Andarist

Mateusz Burzyński (Andarist) commented Jul 7, 2019

Copy link
Copy Markdown
Contributor

From what I have understand here - are you saying that improving types around co-like libraries is not on the schedule of 3.6? I was kinda hoping that advertised "improved generators support" was all over that. I might be biased (redux-saga maintainer here) but implementing all sort of interpreters with generators is a really cool usage and was hoping that upcoming changes would finally help express those patterns in TS.

samhh, hilkeheremans, raveclassic, Moejoe90, neurosnap, and cogell reacted with thumbs up emoji
All reactions
  • 👍 6 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@treybrisbane

Trey Brisbane (treybrisbane) commented Jul 7, 2019

Copy link
Copy Markdown

Mateusz Burzyński (@Andarist) It sounds like your use case is the same as what Troy Gerwien (@yortus) mentioned above. If so, you're correct in that this PR does not address that. Such a use case requires type-level higher-order functions, the implementation of which would be a much more fundamental change to the type system, and is very much beyond the scope of this work.

Unfortunately, there do not seem to be any plans (that I can find) to add such a feature to the language. :(

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JoshuaKGoldberg

Josh Ghoulberg 👻 (JoshuaKGoldberg) commented Jul 16, 2019

Copy link
Copy Markdown
Contributor

This appears to be the root cause of palantir/tslint#4784.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JoshuaKGoldberg Josh Ghoulberg 👻 (JoshuaKGoldberg) mentioned this pull request Jul 16, 2019
Allowed new 'AsyncGenerator' name for await-promise async iterables palantir/tslint#4800
Merged
3 tasks done
@kgtkr kgtkr (kgtkr) mentioned this pull request Jul 22, 2019
[Bug]stricter Generators: T not in scope #32507
Closed
@yortus Troy Gerwien (yortus) mentioned this pull request Jul 24, 2019
Generator: infer the type of yield expression based on yielded value #32523
Closed
@Kamahl19 Martin Litvaj (Kamahl19) mentioned this pull request Jul 24, 2019
Update redux-saga usage docs piotrwitek/typesafe-actions#175
Open
@rbuckton
Ron Buckton (rbuckton) deleted the strictGeneratorTypes branch July 27, 2019 19:32
@rbuckton Ron Buckton (rbuckton) mentioned this pull request Aug 2, 2019
Iterable and AsyncIterable interfaces should have full type arguments #32682
Closed
Josemar Luedke (josemarluedke) pushed a commit to josemarluedke/ember-decorators that referenced this pull request Aug 6, 2019
@buschtoens @josemarluedke
fix(deps): upgrade @types/node@^9.6.48
858c86c
microsoft/TypeScript#30790 (comment)
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) mentioned this pull request Aug 21, 2019
Type Iterator#next() argument (yield expression) #32998
Closed
5 tasks done
@humanchimp Chris Thorn (humanchimp) mentioned this pull request Aug 29, 2019
add lib.2018.asyncgenerator to default lib names wessberg/rollup-plugin-ts#26
Merged
This was referenced Sep 4, 2019
Trouble implementing AsyncIterator interface in 3.6.2 #33239
Closed
Unable to use done property of IteratorResult to narrow types in typescript 3.6.2 #33241
Closed
Generators/Async Generators with TReturn type argument which extends undefined have a return method with a non-optional argument in 3.6.2 #33357
Open
@brainkim Brian Kim (brainkim) mentioned this pull request Nov 7, 2019
Generator functions which have a return type of a union of Iterator/AsyncIterator have a yield type of never #34984
Open
@ExE-Boss ExE Boss (ExE-Boss) mentioned this pull request Feb 15, 2020
Allow specifying TReturn and TNext for AsyncIterableIterator and AsyncIterable #36723
Closed
@tadhgmister Tadhg McDonald-Jensen (tadhgmister) mentioned this pull request Feb 24, 2020
Feature request: typed yield expression #36967
Open
5 tasks done
@harrysolovay Harry Solovay (harrysolovay) mentioned this pull request Nov 12, 2020
Misc discussion thread tjjfvi/tjjfvi.github.io#1
Open
@treybrisbane Trey Brisbane (treybrisbane) mentioned this pull request May 31, 2021
💡 Yield Overrides #43632
Open
5 tasks done
@Jessidhia Jessica Franco (Jessidhia) mentioned this pull request Oct 26, 2022
RFC: First class support for promises and async/await reactjs/rfcs#229
Open
@vezaynk Slava Knyazev (vezaynk) mentioned this pull request Mar 12, 2023
Incorrect type for Set.prototype.values().next Iterator #53223
Closed
This was referenced Apr 30, 2024
Add TReturn/TNext to Iterable et al #58243
Merged
Iterators/Generators, next(), and unsafe yield statement types #58381
Closed
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sandersn Nathan Shively-Sanders (sandersn) sandersn approved these changes
@weswigham Wesley Wigham (weswigham) weswigham approved these changes
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) RyanCavanaugh approved these changes
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Awaiting requested review from DanielRosenwasser
@ahejlsberg Anders Hejlsberg (ahejlsberg) Awaiting requested review from ahejlsberg
+5 more reviewers
@MattiasBuelens Mattias Buelens (MattiasBuelens) MattiasBuelens left review comments
@sergey-shandar Sergey Shandar (sergey-shandar) sergey-shandar left review comments
@Igorbek Igor Oleinikov (Igorbek) Igorbek left review comments
@ExE-Boss ExE Boss (ExE-Boss) ExE-Boss left review comments
@felixfbecker Felix Becker (felixfbecker) felixfbecker left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@sandersn Nathan Shively-Sanders (sandersn)

@rbuckton Ron Buckton (rbuckton)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Update declaration of ts.Iterator to be compatible with ES2015 IteratorResult type yield operator in generator functions has any return type Suggestion: make throw and return required fields for generators Warning when writing a generator function without any yield Boolean literal types and return type propagation for generators

Uh oh!

There was an error while loading. Please reload this page.

20 participants

@rbuckton @typescript-bot @yortus @xaviergonz @treybrisbane @paldepind @Igorbek @MattiasBuelens @falsandtru @felixfbecker @brainkim @Jessidhia @sirian @Jamesernator @ExE-Boss @weswigham @fatcerberus @buschtoens @Andarist @JoshuaKGoldberg
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.