Replies: 1 comment
-
This would be a good thing to add, along with serialize/deserialize options. Created an issue to track it: #1173 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
While the ability to define the storage data type when using functions like
storage.defineItem<Type>()
is convenient, it's sadly not really type-safe - the contents of the storage can be modified either by code not using the same storage util, or even manually, so it's not guaranteed that we always get data of typeType
when usinggetValue()
.The idea is to allow passing a schema (preferably a zod schema) against which the value read from the storage would be validated internally in
getValue()
before being returned. A nice bonus is that it would be easy to automatically infer the type based on the schema, so the dev wouldn't have to specify it on top of the schema.It could look sth like this:
and the types for
defineItem()
would go sth like this:Alternatively, if we wanted to avoid vendor-lockin on zod, we could just have a
validate
parameter:Beta Was this translation helpful? Give feedback.
All reactions