Skip to content

Why the recursive function's return type inferenced as any? #53978

Closed
@nnnnoel

Description

@nnnnoel

Bug Report

when write recursive function via generator function or function,
return type inferenced as any.
the general purpose for recursive function, return type can be inferenced as correct return type.

🔎 Search Terms

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

image

function mock__fstat(name: string) {
    if (Math.random() > 0.5) {
        return {
            isDirectory: true,
            isFile: false,
        };
    }
    return {
        isDirectory: false,
        isFile: true,
    };
}
function* walk(dir: string) {
    if (mock__fstat(dir).isDirectory) {
        yield* walk(dir.split('/').slice(1).join('/'));
    }
    yield dir;
}
const a = walk('/a/b/c'); // will be AsyncGenerator<string>, but inferenced type is any

🙁 Actual behavior

walk function's return type is any

🙂 Expected behavior

walk function's return type is AsyncGenerator

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions