Replies: 2 comments 2 replies
-
Solid stores have read/write segregation, which means when creating the following store const [store, setStore] = createStore({ todos: [] ]); The I do agree |
Beta Was this translation helpful? Give feedback.
-
Trying to add or remove the readonly modifier recursively is actually quite troublesome. Previously the store returned by createStore was completely readonly, but self-referencing types and generic types don't play well with recursive readonly, producing confusing error messages. Also many people were confused as to why their functions accepting non-readonly-typed store types wouldn't accept their stores. Typescript also has no way to differentiate classes and plain objects, so classes would be wrongly made (not) readonly unless manually configured otherwise by extending an interface. Maybe most importantly, another way of indicating that something is actually runtime-readonly (e.g. a property getter) would be necessary, otherwise we would be introducing the possibility of a runtime error in exchange for moving a runtime warning to a compile time error. As such I don't see this proposal working. You can still manually type the store and not the setter as readonly, or overload |
Beta Was this translation helpful? Give feedback.
-
Proposal
Remove TypeScript
readonly
from thedraft
type of theproduce
function. This is the wayimmer
works — https://github.com/immerjs/immer/blob/8e12c78073c5f7c3a556a76dd780125b23bb12a3/src/types/types-external.ts#L35-L48.Code example
The code below produces a TypeScript error and it shouldn't. The code will work correctly during runtime.
Current implementation
Currently, Solid will warn when you try to update the store directly. This is great. However, if I add
readonly
to the type I will start getting compile-time errors instead of runtime errors and this improves DX.P.S.: I searched for similar proposals but couldn't find one. I'm new to solid, so I'm sorry if this has been discussed elsewhere.
Beta Was this translation helpful? Give feedback.
All reactions