Stricter known Object Key enforcement change proposal #44
Replies: 1 comment
-
I never got around to blasting this out to a broad audience to feedback, mostly because of the Reddit strike since I was unable to post to I have decided that this change falls under the category of what I'm calling "Type Safety" and should be merged in as "Breaking" but without a Mainly because this update is what I consider to be a fix for current behavior to what it should be. The current typings I consider to be "broken" in this regard I have 2 MRs up to start with this |
Beta Was this translation helpful? Give feedback.
-
Ramda functions like
assoc
current have the ability to set any property on an object. While there is nothing wrong with that, our current typescript definition forassoc
allows for that by default in a non-type-safe wayLet's take a look at a pure javascript example
In typescript, 90% of the time we work with strict object shapes
And repeating the above example
The existing type definition for
assoc
, while does care about the type ofobj
, allows you to set unknown properties by altering the type definition of the input object with the key/value it setsIMHO, this side-steps the typescript' type-safety system
Even misspellings would be let through
I am proposing that
assoc
,assocPath
,prop
, lensProp`, etc, basically any function that references obj keys directly, have their type definitions be changed to only allow for known keys.This would align with what I believe is one of the core intentions of typescript. This would also be a major breaking change
Please note that objects that have mapped properties will still work as expected here
This is because the behavior would be no different from object literal getter/setters for the type
Record<string, number>
In cases where you are using
assoc
orset
to specifically alter the type from one to another, the same casting would be needed as if you were doing an in-place mutationAs previously mentioned, this significantly breaks the current typing behaviors for many functions of
ramda
(I'll add a complete list of those functions later)What I'm looking for here and now is community feedback on if this would need to be a
0.30.0
update or even a1.0.0
update. Even if that semver bump is just for types and not for any actual behavior.Beta Was this translation helpful? Give feedback.
All reactions