Handle union type in store
Hi peeps,
I would like to store union type like this
type Post = NewPost | DeletedPost;
in a store.
https://playground.solidjs.com/anonymous/7210c31b-5730-4e51-b875-3d8e2f36af4c
It seems to work but I wonder if there is a way to tell solid more about the types and avoid type check errors?
Thanks!2 Replies
this is a situation where everything sucks and while we could allow setting the property that's only on some subset of the union, it would be potentially incorrect since you might end up with some type that isn't in the union to begin with, and it would also make typechecking less performant
in the simple case here where
DeletedPost
only has extra properties when compared to NewPost
the suggested solution is probably to just not use a union, but in more complex cases e.g. if NewPost
had another property, that isn't possible without giving up the typechecking provided by the unionThanks, yeah it is not ideal