Skip to content

fix(docs): make the prefault example runnable (declare const schema)#6063

Open
DucMinhNe wants to merge 1 commit into
colinhacks:mainfrom
DucMinhNe:fix/prefault-example-missing-const
Open

fix(docs): make the prefault example runnable (declare const schema)#6063
DucMinhNe wants to merge 1 commit into
colinhacks:mainfrom
DucMinhNe:fix/prefault-example-missing-const

Conversation

@DucMinhNe

Copy link
Copy Markdown

Summary

The second example in the Prefaults section of api.mdx is not runnable:

z.string().transform(val => val.length).prefault("tuna");
schema.parse(undefined); // => 4

The first line is a dangling expression — schema is never declared — and the second line then calls schema.parse(...) on an undefined binding. Copy-pasting this throws a ReferenceError (or, if a schema from a previous block is in scope, silently uses that one, which returns 0, contradicting the // => 4 comment).

Every parallel example in the surrounding Defaults/Prefaults/Catch sections binds const schema = ... — including the default(0) example directly above this one.

Change

Prepend const schema = so the example is self-contained and correct:

const schema = z.string().transform(val => val.length).prefault("tuna");
schema.parse(undefined); // => 4

Now prefault feeds "tuna" through the string → length transform, yielding 4 as the comment states. Docs-only change.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — docs-only fix adding the missing const schema = binding to the prefault code example so it's self-contained and runnable.

  • Add const schema = to prefault docs example — the dangling expression z.string().transform(…).prefault("tuna") followed by schema.parse(undefined) would throw a ReferenceError on copy-paste. Binding const schema = makes the example consistent with every parallel example in the Defaults/Prefaults/Catch sections.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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.

1 participant