-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Refinement in async function #61365
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
Comments
Duplicate of #9998. There's even a dedicated issue template for this exact issue: https://github.com/microsoft/TypeScript/blob/main/.github/ISSUE_TEMPLATE/types-not-correct-in-with-callback.md?plain=1 |
@MartinJohns It's not obvious to me that the same is true for an An Anyway, I wasn't able to find the precedent here so if this still counts as a duplicate I can close and it's up to you if you think it warrants adding to the FAQ / template. |
Since there seems to be discussion here #9998 (comment) I'll just close though. |
π Search Terms
"refinement async function"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?target=99&ts=3.8.3#code/IYZwngdgxgBAZgV2gFwJYHsIwEbAE4AUAlDAN4CwAUDDTHgKbIJ5YT0DuMACnugLaoQ9AgGsYAXgB8MIcgAqqPvXQJkogDQwAjAAYdRIgG4qAXypVQkWIhQYscdOmJkqtGABtGMZPRDIAXDAQCO7uMAA+ZDAAFvSh6IEA5OzoeO4AJokwJhJBIe7G1LRQmCDongB07ugA5gSJ0agAhIlE5kU0sgpKKmrOUi4dbt6+yLmkMXHVSSlpmWZDJm2UrrTA7MCoY7iERqs0JRBlldV1iT5+APyJmhfIy8MA9I90SBCoEDXesTAADrw1PDAPgyaLodggb7AMZ3GCCGAAAwmsXiM1SGSyJgROFUMDkYF+9AAylA8KhfmMPiU8AwoMh3GAYPsaM86PQ4B9fHCYeg8qFNEJ6AJPgy4TUIKkPl9kNFod96AxEpDgFh1psxuxGlBojA+MBGcB4pwZfQYKAQKhxUoIDyYsBfoT7Kg8H5mXdLhUUdVCgsqA4nHsVpQgA
π» Code
π Actual behavior
Getting a type error, where TypeScript refined the type of
test
tonull
π Expected behavior
The inferred type of
test
should benull | { hello: 'world' }
Additional information about the issue
There seems to be an issue where TypeScript ignores awaits (and yield/yield*) when doing refinement. It seems to me that at any point after an await you can no longer assume a refinement holds true.
I understand perhaps this may be a necessary tradeoff to avoid false negatives in many cases. However since there is an explicit assignment to a
let
declared variable in the same function it seems a bit funny. If this is a known limitation perhaps an entry in the FAQ could be added.The text was updated successfully, but these errors were encountered: