You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across a use-case of D.update and D.updateUnsafe that gave me a bit of trouble wrt. its typing.
Example (granted, a bit contrived):
// If I have an object of this shapeconstmyObject={name: string;};// And then use D.update / D.updateUnsafe to change nameconstmyChangedObject=D.updateUnsafe('name',object=>object.name.split(''));
Intuitively, I'd expect the type of myChangedObject.name to be string[], but in practice, it becomes string & string[] (i.e. the original type of name is combined with the return type of the updater function).
Looking at the typings of D.update and D.updateUnsafe, the result of my example definitely makes sense, but I'm wondering a bit why the typings includes the original type of the updated property to begin with 🤔
Happy to hear your takes on this!
The text was updated successfully, but these errors were encountered:
btw, unlike other fp languages, typescript can infer keyof T type in compile-time, so the value of T[K] should be typeof T[K] instead of Option<T[K]>, I guess.
I came across a use-case of
D.update
andD.updateUnsafe
that gave me a bit of trouble wrt. its typing.Example (granted, a bit contrived):
Intuitively, I'd expect the type of
myChangedObject.name
to bestring[]
, but in practice, it becomesstring & string[]
(i.e. the original type ofname
is combined with the return type of the updater function).Looking at the typings of
D.update
andD.updateUnsafe
, the result of my example definitely makes sense, but I'm wondering a bit why the typings includes the original type of the updated property to begin with 🤔Happy to hear your takes on this!
The text was updated successfully, but these errors were encountered: