glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
12.12k stars 1.06k forks source link

fix: Typescript zod (and effect) language uses block scoped variables before they've been declared #2419

Closed kriswest closed 7 months ago

kriswest commented 11 months ago

By ensuring that referenced types are defined before they are referenced. Tested on a fairly large set of interconnected schemas for the bridging API in the FDC3 standard.

Please let me know if there's a more idiomatic way to get to the types underlying sets, unions, intersections, arrays etc..

resolves https://github.com/glideapps/quicktype/issues/2414

@ryoid @Southclaws @dvdsgl P.S. The TypeScript effect schema language uses the same code in its generation and probably also needs these changes - I don't have a test set-up for that one however.

kriswest commented 8 months ago

@ryoid @Southclaws @dvdsgl any chance of a review on this PR? I believe it straightens out issues with generated typescript zod code in the current release.

dvdsgl commented 8 months ago

Yep! Will review next weekend.

kriswest commented 8 months ago

Much appreciated @dvdsgl

dvdsgl commented 7 months ago

I’m pretty sure the type graph already provides this for other languages where declaration order matters, although I am not sure where that functionality is. I think we can still merge this however, and replace it if there’s a built-in way to do it.

dvdsgl commented 7 months ago

Thank you!

kriswest commented 7 months ago

🎉

I’m pretty sure the type graph already provides this for other languages where declaration order matters, although I am not sure where that functionality is. I think we can still merge this however, and replace it if there’s a built-in way to do it.

I did wonder if that was the case - but couldn't figure it out. If you come across the info let me know and I might be able to contribute a replacement using it one day.