-
Notifications
You must be signed in to change notification settings - Fork 38
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
Update when we can infer void
from a function body
#468
Labels
Comments
For completeness: This requires to traverse into every block-like scope to potentially find return types: export function foo() {
for (let i = 0; i < 10; i ) {
if (i === 10) {
return 42
}
}
} |
We already do that 👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now we sometimes incorrectly infer the function return type due to our
return
statement analysis. The only cases where we can safely infervoid
is when:Notably, we can not infer a function expression from expressions such as
() => { n() }
, because the return type may benever
ifn()
returnsnever
.Sync functions: https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXxAA8sMAKASgC55UQA3EGAbgCgWiAHHGDJNTXPigV4AbxbxJBYmXKsAvm07deKdNjzwARiPFT4cDMhioWi9oS48 6wfDC6JUrInikA5hBxaoEACoAFlgAzuRiTvqSRCQUrPqK obGpubK1moCmsCO mZKlir2eMG8CAC8bmFlAHzh tGyCvlWvGDFqvAVIjV1UkkmeRYtRagl8O6dlZ21es6uHl4 -kGhvZHSMXIR8Al9IEYDqQXWbaO8AZPdM9uDaa3t8FiTGRqoOVINsbfH92fwAFbPfivd6SfopZqFU5jADWQNseFBj3mnm8vkCITCs3Wny28W24O w2hvAg8MybyxN3kQA
Async functions: https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXxAA8sMAKASgC55UQA3EGAbgCgWiAHHGDeKAZwCe6JGky58UCvADeLeAoLEy5VgF82nbrwHCwo9NjzwARtLmL4cDMhioWG9oS48 QkSkMT4Yc-MVYiPCkAOYQOCZQEAAqABZY-OSy-pYKRCQUrJYalta29o5arroeYkb4wH6WDprO2j54-LwIALxuesFJLQB8yZbpKuq1LrxgjbxBbSX60j19inl2NU4jDahN8CHwU 4zXb0WAUGh4ZEx8YnzqUoZqinwOQsgNkuFda5j67yx2 0iswd7ssiqNxvAsL9pgZxHgqooBplge9QV94AArSG7aHlOEKRYFYb1T4bADWmI6nhhqFx4OOYQiUTiCSSh2uCLu2Xu KRq2JvAg5NKXlhLLYaiAA
The text was updated successfully, but these errors were encountered: