-
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
Incorrect type inferred after threading destructured object with getter #54577
Comments
I'm not really sure how this could be fixed given the current design of the type system, unless you're proposing that
Poor Josh, what did he ever do to anyone to deserve this? 😄 |
🙈 He's too cool to hang out with Sammy!
Yeah, that's what I kind of had in mind, though as you say:
I half hoped that TypeScript kept some internal knowledge about the getters and that the displayed type (e.g. I think I'll just need to be careful when using getters! To be honest I didn't actually come here expecting an easy fix hehe |
Yeah, if you directly have a type (like |
Essentially the same as #26547. TS doesn't currently track own/enumerable properties on types; it can do so for classes because it knows which things are actually going to end up on the prototype vs the instance, but when you indirect through types then such information can't be represented. |
This issue has been marked as 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
Javascript will not call getters when destructuring an object:
TypeScript correctly infers this when such an object is used directly:
If the object is threaded through another function however, the (getter) type information seems to get lost:
🔎 Search Terms
typescript, getter, destructuring
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
TypeScript did not warn that
{... person}
did not have thename
field anymore🙂 Expected behavior
TypeScript should have warned that the getters have not been called
The text was updated successfully, but these errors were encountered: