Closed
Description
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
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