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
clear(): void{this.store=createPlainObject();// <-- set store to an empty object, which will in turn emit a change event where current = {}for(constkeyofObject.keys(this.#defaultValues)){this.reset(key);// <-- reset keys, without emitting a change event}}
As you can see, we emit a change event with a blank object, and don't properly emit the post-reset() store.
Noticing this illuminated the following static typing predicament:
suppose we initialize a Conf:
typeMyType={foo: number}constconf=newConf<MyType>()// <-- this should require a defaults property with a value of type MyType
Instead of following this, the internal implementation basically always assumes that defaults is a Partial<T> and that the Conf, despite its type being MyType, is actually only Partial<T>. For practical use and type safety, the Conf should statically type to T (MyType in my example), notPartial<T>. If not, and you want to stick with Partial<T> it's critical that
get store()'s method header is rewritten to
getstore(): Partial<T>
because either following a reset() or from the very onset with a partial defaults object, the client cannot be sure that the store is of type T.
The text was updated successfully, but these errors were encountered:
With this fix landed, a new bug in
clear()
has become evident.As you know, settings
.store = ...
emits achange
event.The code for clear() is currently as follows:
As you can see, we emit a change event with a blank object, and don't properly emit the post-reset() store.
Noticing this illuminated the following static typing predicament:
suppose we initialize a Conf:
Instead of following this, the internal implementation basically always assumes that defaults is a
Partial<T>
and that the Conf, despite its type being MyType, is actually onlyPartial<T>
. For practical use and type safety, the Conf should statically type toT
(MyType
in my example), notPartial<T>
. If not, and you want to stick withPartial<T>
it's critical thatget store()
's method header is rewritten tobecause either following a
reset()
or from the very onset with a partial defaults object, the client cannot be sure that the store is of typeT
.The text was updated successfully, but these errors were encountered: