Skip to content

Avoid non null assertion in toJSONSchema#5638

Merged
colinhacks merged 1 commit intocolinhacks:mainfrom
samchungy:prevent-flattening
Jan 22, 2026
Merged

Avoid non null assertion in toJSONSchema#5638
colinhacks merged 1 commit intocolinhacks:mainfrom
samchungy:prevent-flattening

Conversation

@samchungy
Copy link
Contributor

Howdy doody, this little line is throwing and reported via one of my repos.

Minimal Repro:

import * as z from 'zod';

console.log(
  z.toJSONSchema(
    z
      .string()
      .meta({ id: 'foo', description: 'foo' })
      .describe('bar')
      .optional(),
  ),
);

To be honest, I haven't taken too much time to understand what this bit of code is doing but adding a conditional before seems to work.

Resolves samchungy/fastify-zod-openapi#352

@pullfrog
Copy link
Contributor

pullfrog bot commented Jan 15, 2026

Pullfrog  | Review this ➔pullfrog.com

@samchungy samchungy changed the title toJSONSchema: Avoid non null assertion Avoid non null assertion in toJSONSchema Jan 22, 2026
@dan-lee
Copy link

dan-lee commented Jan 22, 2026

We are also seeing this error, would be great if fixed.

Found similar PRs: #5639 #5644 #5636

@colinhacks colinhacks merged commit cbf77bb into colinhacks:main Jan 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Zod v4.3+] Cannot use 'in' operator to search for 'description' in undefined

3 participants