Skip to content

feat(experimental): allow null when schema is optional - #200

Merged
ping-maxwell merged 1 commit into
better-auth:experimentalfrom
ping-maxwell:experimental
Sep 1, 2026
Merged

feat(experimental): allow null when schema is optional#200
ping-maxwell merged 1 commit into
better-auth:experimentalfrom
ping-maxwell:experimental

Conversation

@ping-maxwell

Copy link
Copy Markdown
Collaborator

optional already meant undefined may pass; treat null the same so callers and handlers share one nullish absence model.

optional already meant undefined may pass; treat null the same so
callers and handlers share one nullish absence model.
@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/better-call@200

commit: 6eca0b5

@ping-maxwell
ping-maxwell merged commit 01ff4b7 into better-auth:experimental Sep 1, 2026
6 checks passed
@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown

Greptile Summary

This PR extends experimental optional schemas so explicit null follows the same runtime absence behavior as undefined and widens inferred outputs accordingly.

  • Passes null through for optional schemas without defaults and applies defaults when present
  • Widens optional output and function-schema types to include null
  • Adds runtime and type-level coverage for optional null values

Confidence Score: 4/5

The PR should not merge until optional schemas with defaults expose null in their typed input contract consistently with runtime validation.

Runtime validation now deliberately accepts null and applies defaults, but InferArgs and FieldIn still reject null whenever a concrete default is declared, leaving typed callers unable to use part of the new behavior.

Files Needing Attention: packages/experimental/src/schema.ts

Fix all with Greploop Fix All in Cursor Fix All in Codex Fix All in Claude Code

Reviews (1): Last reviewed commit: "feat(experimental): allow null when sche..." | Re-trigger Greptile

Comment on lines +338 to +341
: I extends TypeDefination<infer T, any, infer D>
? undefined extends D
? T | null
: T

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Defaulted inputs still reject null

When an optional schema declares a default, runtime validation accepts null and substitutes that default, but InferArgs and FieldIn still exclude null because D is concrete. Typed direct calls and object fields therefore reject inputs that the new runtime contract deliberately accepts.

Knowledge Base Used: Validation and schema contracts

Fix in Cursor Fix in Codex Fix in Claude Code

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