Skip to content

fix(conform-react): expose undefined from DefaultValue<Shape> when Shape is generic - #1404

Open
transparent-citizen wants to merge 1 commit into
edmundhung:mainfrom
transparent-citizen:main
Open

transparent-citizen wants to merge 1 commit into
edmundhung:mainfrom
transparent-citizen:main

Conversation

@transparent-citizen

@transparent-citizen transparent-citizen commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

I noticed a type error when trying to wrap useForm generically using exactOptionalPropertyTypes.

The error can be worked around by typing the generic defaultValue as DefaultValue<Shape> | undefined. This is unexpected, since Conform's definition of DefaultValue already includes | null | undefined.

It fails to infer undefined, because the | null | undefined appears in the conditional branches. Moving them out and hoisting them up fixes it. But beware: The parens are required!

I've also added a regression test and made sure that the old definition of DefaultValue fails it.

Feel free to let me know if there's anything else I can do.

Generated Summary

Fixes the DefaultValue<Shape> type so generic wrappers accept undefined. Callers no longer need DefaultValue<Shape> | undefined.

Changes in packages/conform-react/future/types.ts:

  • null | undefined moves out of the conditional branches to the top level of the union.
  • The file branch changes from null | undefined to never.
  • The string branch changes from Shape | null | undefined to Shape.
  • The fallback branch changes from Shape | string | null | undefined to Shape | string.
  • Object and array branches drop their | null | undefined suffix.
export type DefaultValue<Shape> =
	| null
	| undefined
	| (Shape extends Record<string, any>
		? { [Key in keyof Shape]?: DefaultValue<Shape[Key]> }
		: Shape extends Array<infer Item>
			? Array<DefaultValue<Item>>
			: Shape extends File | File[]
				? never
				: Shape extends string | null | undefined
					? Shape
					: Shape | string);

Other changes:

  • packages/conform-react/tests/types.test-d.ts: adds a type test. A generic <Shape>() => DefaultValue<Shape> accepts both null and undefined.
  • .changeset/strong-pandas-return.md: adds a minor changeset for @conform-to/react.

Nested object and array values no longer accept null or undefined by default. Only the top level does.

@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4d50cc1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@conform-to/react Minor
@conform-to/dom Minor
@conform-to/valibot Minor
@conform-to/yup Minor
@conform-to/zod Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

DefaultValue<Shape> now permits null and undefined at the top level. Nested object properties and array items do not gain those values through recursion. A type-level test covers generic returns, and a changeset records the update.

Changes: DefaultValue nullability

Layer / File(s) Summary
DefaultValue type and validation
packages/conform-react/future/types.ts, packages/conform-react/tests/types.test-d.ts, .changeset/strong-pandas-return.md
DefaultValue<Shape> handles nullish values at the top level, while recursive object and array values retain their nested types. A type-level test checks generic returns of null and undefined. The changeset declares a minor release for @conform-to/react.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: edmundhung

Merge Risk: Minimal · up to f81a6

This is a small type-only fix that lets generic callers return null or undefined from DefaultValue. It is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title names the main change: a fix in conform-react so that DefaultValue exposes undefined when Shape is generic. The raw summary confirms DefaultValue was changed to allow top-level null |…
Full details: Title check

Explanation

The title names the main change: a fix in conform-react so that DefaultValue<Shape> exposes undefined when Shape is generic. The raw summary confirms DefaultValue was changed to allow top-level null | undefined, and a type test was added for the generic case. The title is specific and matches the changeset. Its length (87 characters) is long but acceptable.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the types with care
Null and undefined now appear
At top level, not nested deep
The tests record what types can keep
A changeset marks the update there

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ed521f4c-0979-4ded-9d9a-9c14fc55c897
Commits

Reviewing files that changed from the base of the PR and between 22bc902 and f81a6c6.

Files selected for processing: 3

  • .changeset/strong-pandas-return.md
  • packages/conform-react/future/types.ts
  • packages/conform-react/tests/types.test-d.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 16

  • GitHub Check: Future API Tests (windows-latest, chromium, 22)
  • GitHub Check: E2E Tests (ubuntu-latest, firefox, 22)
  • GitHub Check: Future API Tests (macos-latest, chromium, 22)
  • GitHub Check: E2E Tests (ubuntu-latest, webkit, 22)
  • GitHub Check: Future API Tests (macos-latest, webkit, 22)
  • GitHub Check: Future API Tests (ubuntu-latest, chromium, 22)
  • GitHub Check: Future API Tests (ubuntu-latest, webkit, 22)
  • GitHub Check: E2E Tests (ubuntu-latest, chromium, 22)
  • GitHub Check: E2E Tests (macos-latest, webkit, 22)
  • GitHub Check: E2E Tests (windows-latest, chromium, 22)
  • GitHub Check: E2E Tests (macos-latest, chromium, 22)
  • GitHub Check: Release
  • GitHub Check: Typecheck
  • GitHub Check: Future API Tests (ubuntu-latest, firefox, 22)
  • GitHub Check: API Tests (v1)
  • GitHub Check: CodeRabbit
Additional context used

markdownlint-cli2 (0.24.0)

.changeset/strong-pandas-return.md

[warning] 5-5: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

@pkg-pr-new

pkg-pr-new Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
More templates

@conform-to/dom

npm i https://pkg.pr.new/@conform-to/dom@1404

@conform-to/react

npm i https://pkg.pr.new/@conform-to/react@1404

@conform-to/valibot

npm i https://pkg.pr.new/@conform-to/valibot@1404

@conform-to/validitystate

npm i https://pkg.pr.new/@conform-to/validitystate@1404

@conform-to/yup

npm i https://pkg.pr.new/@conform-to/yup@1404

@conform-to/zod

npm i https://pkg.pr.new/@conform-to/zod@1404

commit: 4d50cc1

@transparent-citizen transparent-citizen changed the title Fix DefaultValue<Shape> to expose undefined when Shape is generic fix(conform-react): expose undefined from DefaultValue<Shape> when Shape is generic Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test is very concise and can be read as:

Is null visible in DefaultValue<Shape> without reducing the conditional?

L317: If you have a wrapper function GenericDefault that returns a DefaultValue<Shape>, then

L319: any function of signature () => null matches the type GenericDefault. Reason: null must be assignable to DefaultValue<S> for every S the caller chooses, and returning null satisfies that for every Shape.

L320: Same argument, but with undefined.

The fact that the previous definition of DefaultValue fails this test but this PR's definition doesn't, implies that hoisting helps TypeScript prove the correctness of more cases. It also follows an algebraic transformation that looks like factoring out a value from a sum, basically applying the distributive law over sum types:

(A × C) + (B × C) = (A + B) × C

This branch has not been deployed

No deployments
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