-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
TS does not automatically understand object with accessor type if not extracted to a variable #46111
Comments
Looks like duplicate of #44899 which considered duplicate of #10530 (that accumulated a lot of different cases in comments e.g. #10530 (comment)) |
I think this PR #45974 handles this case. Playground |
Yes @a-tarasyuk . That would cover this case. Nice π |
Yes @IllusionMH those two iseues seem like to be a better way of expressing what I wanted. Thanks. π I think this issue can/should be closed. |
@a-tarasyuk great work as always! However is it safe to do this case if |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
extract to variable accessor, accessor automatically infer
π Version & Regression Information
].
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
There are two functions at the bottom of the code. The only difference is that in second case, I extracted
myVariable[key]
to a variable and used that in if condition and return value. In first function it gives me error, but in the second one (extracted variable) it doesn't.π Expected behavior
I expected TypeScript to automatically infer
myVariable[key]
is an object inside theif
condition withisItObject(myVariable[key])
The text was updated successfully, but these errors were encountered: