iway1 / react-ts-form

https://react-ts-form.com
MIT License
2.01k stars 33 forks source link

fix unwrap for default, arrays of enums, and generally all unwrappables in every order we support #135

Closed scamden closed 10 months ago

scamden commented 11 months ago

I noticed our unwrap types didn't work for .default() even though the runtime code did. I've also seen a bug where z.enum().array() doesn't match either (because we didn't unwrap the enum type of the array element).

The solution to all of this (and a few other possible differences in order) was to make the unwrap recursive. However, the type had a comment mentioning that previously that created a stack overflow.

Turns out this is possible (and seems fast) as long as we limit the depth to the max number of unwraps we allow. Similar to what we did with the type recursion in PropType (but much much simpler here)

cc @brettzallen (for the default problem) @matasar-watershed (cause the enum array problem)

vercel[bot] commented 11 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-ts-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2023 0:49am
scamden commented 11 months ago

@iway1 i'm inclined to merge as this fixes a host of issues, but let me know if you are uncomfortable