How can I get TypeScript to automatically output the type of the result of the `yield` call?

In the following code example:

function* gen() {
    let v = yield Promise.resolve(0);
    return v;
}

Type is vdefined as any. I am wondering if there is a way to make it infer another type (say, number) based on contextual prompts.

I know that in this particular scenario I can use async/ awaitinstead, but I'm curious about the general case (when not working with promises).

+4
source share

No one has answered this question yet.


All Articles