Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference of recursive arrow function's return type is any #58100

Closed
hospotho opened this issue Apr 7, 2024 · 2 comments · Fixed by #58124
Closed

Inference of recursive arrow function's return type is any #58100

hospotho opened this issue Apr 7, 2024 · 2 comments · Fixed by #58124
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Milestone

Comments

@hospotho
Copy link

hospotho commented Apr 7, 2024

🔎 Search Terms

recursive function arrow function

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • 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

https://www.typescriptlang.org/play?ts=5.4.4#code/PTAEGMHsDsGcBdQDNKQFygBQEpQF4A+UAQ2gE8AoKORFSfLXQ0AbwtFAEsksBZY+AAsAdACdSAE0gBbHKCIAGYQFZcbDh1EBTeAFdR0ZKhztQAX1Pa9B0AooWKIZLujh4nGKABGxUTgzQutJeWqIUSC5uHoY+fmqm3HwCIuLQUrK4iirxGqBW+jG+JhwWmjoFtvYUQA

💻 Code

// const foo: () => any
const foo = () => {
  if (Math.random() > 0.5) {
    return foo()
  }
  return 0
}

// function bar(): number
function bar() {
  if (Math.random() > 0.5) {
    return bar()
  }
  return 0
}

🙁 Actual behavior

const foo: () => any
'foo' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

🙂 Expected behavior

The inference should be const foo: () => number, even this inference is happened before the arrow function assign to foo

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

Duplicate of #53978. Used search terms: recursive any in:title

@hospotho
Copy link
Author

hospotho commented Apr 7, 2024

Duplicate of #53978. Used search terms: recursive any in:title

They mention a pull request (#53995) related to regular function with self tail calls. Maybe I can update the title to "Self tail calls of arrow function were not ignored"?

@andrewbranch andrewbranch added the Bug A bug in TypeScript label Apr 8, 2024
@andrewbranch andrewbranch self-assigned this Apr 8, 2024
@andrewbranch andrewbranch added this to the Backlog milestone Apr 8, 2024
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants