Skip to content

Recursive async function return type not inferred when await on the self callΒ #55973

Closed
@miguel-leon

Description

@miguel-leon

πŸ”Ž Search Terms

async recursive await

πŸ•— Version & Regression Information

Latest version

⏯ Playground Link

https://www.typescriptlang.org/play?#code/PTAEEsDsDMFMCcDOoAuBPADrUB3cKALAewFcVQBDHC-AKAsTUgGNRoSWVwjJR5ZmARgAUASlABvWqBkRooYQFkKhAHTwKkACZEAtmNAAeUAAZVAVnFTZNvrBQl4vfkLEBuabIC+oWABtEbGtbGX4HJ1AAcgJ-PyJIjxsvWmTaEAgYBGRNNFx8AkpqOgYmVnZObmcBACYDYJlweSUVAnVNHX1xYzNLSU8QsMdeKhpyF1rRRO9fAKD+20GI6Nj4qZlk5KA

πŸ’» Code

// infers type without await
async function rec1() {
    if (Math.random() < 0.5) {
        return rec1();
    } else {
        return 'hello';
    }
}

// infers any with await
async function rec2() {
    if (Math.random() < 0.5) {
        return await rec2();
    } else {
        return 'hello';
    }
}

πŸ™ Actual behavior

infers any with await on self call

πŸ™‚ Expected behavior

should infer the return type as it does without await

Additional information about the issue

To my understanding, the code has the exact same runtime behavior, so one would expect the same at compilation.

If working as intended? why?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions