With this fix landed, a new bug in clear()
has become evident.
As you know, settings .store = ...
emits a change
event.
The code for clear() is currently as follows:
clear(): void {
this.store = createPlainObject(); // <-- set store to an empty object, which will in turn emit a change event where current = {}
for (const key of Object.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:
type MyType = { foo: number }
const conf = new Conf<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), not Partial<T>
. If not, and you want to stick with Partial<T>
it's critical that
get store()
's method header is rewritten to
get store(): 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
.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too