Skip to content

fix(types): allow undefined in ClassNames values - #3018

Closed
cpruijsen wants to merge 2 commits into
gpbl:mainfrom
cpruijsen:fix/issue-3015
Closed

cpruijsen wants to merge 2 commits into
gpbl:mainfrom
cpruijsen:fix/issue-3015

Conversation

@cpruijsen

Copy link
Copy Markdown

Summary

ClassNames values are string | undefined, so Partial<ClassNames> accepts string | undefined from clsx / cva / similar helpers under TypeScript exactOptionalPropertyTypes (TS2375). Keys stay required; they are not made optional.

The public API change is types-only. Internally, values are narrowed before classList / string[], which is what tsc requires after that change.

Fixes #3015.

Decision

Chose ClassNames values string | undefined, matching Styles and the change proposed in the issue.

The alternative is to keep ClassNames as string and only widen the classNames prop to { [K in keyof ClassNames]?: string | undefined }, so getDefaultClassNames() / useDayPicker().classNames stay definitely string and the animation / modifier helpers need no edits.

Happy to switch to the prop-only widen.

Test plan

  • pnpm --filter react-day-picker typecheck (fails without the ClassNames value change; passes with it)
  • Isolated tsc with exactOptionalPropertyTypes: true assigning { root: string | undefined } to Partial<ClassNames>
  • jest --selectProjects src --testPathPatterns='types/props.test|useAnimation.test|getDefaultClassNames.test'
  • If reviewing locally: pnpm test and pnpm typecheck as in CONTRIBUTING.md

Partial<ClassNames> rejected string | undefined under exactOptionalPropertyTypes. Align ClassNames with Styles so classNames accepts clsx/cva results without making keys optional.
@cpruijsen
cpruijsen requested a review from gpbl as a code owner September 10, 2026 16:54
@changeset-bot

changeset-bot Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f157090

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

This PR includes changesets to release 7 packages
Name Type
react-day-picker Patch
@daypicker/react Patch
@daypicker/buddhist Patch
@daypicker/ethiopic Patch
@daypicker/hebrew Patch
@daypicker/hijri Patch
@daypicker/persian Patch

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

@cpruijsen cpruijsen closed this Sep 30, 2026
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.

Types: allow undefined in ClassNames values (classNames breaks under exactOptionalPropertyTypes)

2 participants