Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ export class TypeScriptZodRenderer extends ConvenienceRenderer {
],
(_enumType) => panic("Should already be handled."),
(unionType) => {
const children = Array.from(unionType.getChildren()).map(
(type: Type) => this.typeMapTypeFor(type, false),
);
const children = Array.from(unionType.getChildren())
// Coercing schemas can accept null, so handle it first.
.sort(
(a, b) =>
Number(b.kind === "null") -
Number(a.kind === "null"),
)
.map((type: Type) => this.typeMapTypeFor(type, false));
return ["z.union([", ...arrayIntercalate(", ", children), "])"];
},
(_transformedStringType) => {
Expand Down
3 changes: 0 additions & 3 deletions test/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1879,9 +1879,6 @@ export const TypeScriptZodLanguage: Language = {
// Does not handle top level array
"bug863.json",

// z.coerce.date() coerces null to the Unix epoch: #2880
"bug2590.json",

"no-classes.json",
"00c36.json",
"10be4.json",
Expand Down
Loading