Skip to content

Commit

Permalink
fix(zui): chaining optional nullable should still be optional (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
franklevasseur authored Sep 28, 2024
1 parent 0acfad9 commit 4b1f571
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion zui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bpinternal/zui",
"version": "0.10.3",
"version": "0.10.4",
"description": "A fork of Zod with additional features",
"type": "module",
"source": "./src/index.ts",
Expand Down
3 changes: 1 addition & 2 deletions zui/src/transforms/zui-to-typescript-next/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ describe.concurrent('objects', () => {
await expect(typings).toMatchWithoutFormatting(expected)
})

// TODO: fix this test
it.skip('chaining nullable optional should still be optional', async () => {
it('chaining optional nullable should still be optional', async () => {
const schema = z.object({
foo: z.string().optional().nullable(),
})
Expand Down
4 changes: 3 additions & 1 deletion zui/src/transforms/zui-to-typescript-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ declare const ${schema.identifier}: ${typings};`)
const delimiter = description?.trim().length > 0 ? '\n' : ''
const withoutDesc = schema.value.describe('')

const optionalModifier = schema.optional ? '?' : ''
// either we are children of a z.ZodOptional or there is a z.ZodOptional in the children
const isOptional = schema.optional || schema.value.isOptional()
const optionalModifier = isOptional ? '?' : ''
return `${delimiter}${description}${delimiter}${schema.key}${optionalModifier}: ${sUnwrapZod(withoutDesc, newConfig)}${delimiter}`
}

Expand Down

0 comments on commit 4b1f571

Please sign in to comment.