Open m-shaka opened 3 weeks ago
Thank you for reaching out! Maybe it is better if Hono wraps the input type in readonly to allow readonly values as input? At the moment readonly
is a transformation action and therefore only affects the output of the schema.
I appreciate your quick response!
Yeah, I understand you think Hono is responsible for it, not Valibot. However, Hono RPC handles tons of types and has a performance issue relating to type calculation. Also, we should transform array types recursively, which is a bit heavy task for the type checker.
So, the point is that my proposal possibly won't break compatibility. ReadonlyArray
is not intuitive here, but does not harm anything, I think
is not intuitive here, but does not harm anything, I think
This is theoretically true, but it breaks the philosophy of our pipe
method. A transformation can only affect the output, not the input. If someone uses the input type somewhere, it may also break their code if they treat it as mutable. 😐
I am still happy to discuss this.
Even if you define a ReadonlyArray schema, you get a writable array type through
InferInput
. However, it could be nicer to make itReadonlyArray
.playground
My use case is Hono RPC. Hono RPC provides you with type information of the request body using a Valibot schema you define
The type of
json.tags
here is Array, so you can't pass aReadonlyArray<string>
value without type assertion, which is a bit annoying.I know Array type is more natural, but making it ReadonlyArray is not harmful. Array is a subtype of ReadonlyArray so you can pass Array as well as ReadonlyArray to a place where ReadonlyArray is expected.