You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to define a property inside the object which is ReadonlyArray, so I did: tags: array(string())
but then when I tried to use the that object in other places of the app TS complained, since ReadonlyArray is a subset of Array (does not implement mutation methods).
Is there a way to do that using refine (since it's a generic) or is it necessary to update superstruct code?
btw. I'm sorry if the question is stupid, I'm quite new to the library - but so far I'm in love with it! Definitely the best runtime TS checker I've seen!
The text was updated successfully, but these errors were encountered:
jakubwolny
added a commit
to jakubwolny/superstruct
that referenced
this issue
Jun 30, 2021
jakubwolny
changed the title
array() only defines mutable Array, not ReadonlyArray
array() and tuple() only define mutable Arrays, not ReadonlyArray
Jul 3, 2021
Sorry for the slow reply here @jakubwolny. Interesting use case. I wonder if it makes sense to have a readonly() struct that would just update the typings to know that it's readonly? (Other than that it's an identity struct.)
@ianstormtaylor that's an awesome idea! for array() it could change the type from Array to ReadonlyArray, and for object() it could add "readonly" modifier for object properties.
My use case is pretty common I guess - I read some data from the API, validate the type, and display it. So I want to make sure that there's no mutation happening somewhere deep down.
I guess I have similar problem to #523
I wanted to define a property inside the object which is ReadonlyArray, so I did:
tags: array(string())
but then when I tried to use the that object in other places of the app TS complained, since ReadonlyArray is a subset of Array (does not implement mutation methods).
Is there a way to do that using
refine
(since it's a generic) or is it necessary to update superstruct code?btw. I'm sorry if the question is stupid, I'm quite new to the library - but so far I'm in love with it! Definitely the best runtime TS checker I've seen!
The text was updated successfully, but these errors were encountered: