diff --git a/zui/package.json b/zui/package.json index 232711a3..e47a4348 100644 --- a/zui/package.json +++ b/zui/package.json @@ -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", diff --git a/zui/src/transforms/zui-to-typescript-next/index.test.ts b/zui/src/transforms/zui-to-typescript-next/index.test.ts index 34a6efba..1c38375a 100644 --- a/zui/src/transforms/zui-to-typescript-next/index.test.ts +++ b/zui/src/transforms/zui-to-typescript-next/index.test.ts @@ -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(), }) diff --git a/zui/src/transforms/zui-to-typescript-next/index.ts b/zui/src/transforms/zui-to-typescript-next/index.ts index b76f1fe4..ed1e6106 100644 --- a/zui/src/transforms/zui-to-typescript-next/index.ts +++ b/zui/src/transforms/zui-to-typescript-next/index.ts @@ -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}` }