I think that we can fully type the value paths of the seconds argument of the decode function using a generic. This way, we can make the API fully type safe. All we need to do is resolve the path of each data type in TypeScript. I have already implemented this in a similar way for Modular Forms.
Furthermore, my idea is that if a generic is specified, for example decode<MyType>(...), the return type of decode is still Record<string, unknown>, and this behavior can be controlled by a second generic, for example a boolean. So decode<MyType, true>(...) would have the return type MyType.
I think that we can fully type the value paths of the seconds argument of the
decode
function using a generic. This way, we can make the API fully type safe. All we need to do is resolve the path of each data type in TypeScript. I have already implemented this in a similar way for Modular Forms.Furthermore, my idea is that if a generic is specified, for example
decode<MyType>(...)
, the return type ofdecode
is stillRecord<string, unknown>
, and this behavior can be controlled by a second generic, for example a boolean. Sodecode<MyType, true>(...)
would have the return typeMyType
.