-
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
Array objects error out when setting a property #43233
Comments
You probably need to expand on that. Why do you think it shouldn't error, when the type definition declares no such property? |
I can't easily get that to work without creating some elaborate TypeScript types to make it valid. I feel that shouldn't be the case. The following is similar for function objects as it works fine: function foobar() {}
foobar.myProp = 1; |
This is intentional behavior and not a bug in TypeScript. Perhaps you want a feature request to treat all objects (or maybe just arrays for some reason) as expando objects, the way function statements are currently. I wonder if this request has happened before... ah, looks like #12416 |
Not really that elaborate:
|
That works if you want the properties to be optional. |
@RyanCavanaugh, do you know if there's any chance of this being implemented, if I raise a feature request? I came across this issue when issue https://styled-system.com/responsive-styles#using-objects. |
Unlikely. This would be a rather huge inference revamp for an initialization style that doesn't see much use. |
Fair enough, thanks. |
Bug Report
Array objects error out when setting a property.
π Search Terms
"array object"
π Version & Regression Information
I've tested it in both v3 and v4.
β― Playground Link
https://www.typescriptlang.org/play?#code/DYUwLgBAZg9jEF4IG0C6BuAUJ2MB0AtgJ4AKATjAA6IQCM6QA
π» Code
π Actual behavior
"Property 'myProp' does not exist on type 'any[]'."
π Expected behavior
It shouldn't error out.
The text was updated successfully, but these errors were encountered: