easy-peasy
easy-peasy copied to clipboard
type system is implemented backwards
Instead of making the user define the types that the store will implement, why don't you just have the compiler figure out the typing from the implimentation itself? That would greatly reduce boilerplate, which is a goal of this library.
createStore<StoreModel>({
doesn't need to take a generic, it can figure it out itself if you write the typescript definition right.
I had considered this, but you might not have all the necessary typing available. Take for instance the following case;
createStore({
session: null,
})
The type inference will be;
type StoreModel = {
session: null;
}
Where really you were likely intending;
type StoreModel = {
session: Session | null;
}
There could be an opportunity to use inference in the case that no model was provided though, as a better fallback, but IMO it will be brittle to optional / union field cases.