-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Type guard fails for a part of an object #31755
Comments
Type guards do not propagate type narrowings to parent objects. The narrowing is only applied upon access of the narrowed property which is why the destructing function works, but the reference function does not. Narrowing the parent would involve synthesizing new types which would be expensive. More detail in this comment. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.4.5
Search Terms: type guard object destructuring, type guard object key
Code
Expected behavior:
Both functions (goodFunction, sameFunction) should be valid typescript code
Actual behavior:
We see TS error
it thinks that
query.group
is steel astring
when passing as arguments, but knows it is aGROUP_TYPE
when gets it from object.Playground Link:
link to playground
The text was updated successfully, but these errors were encountered: