Skip to content

fix(calendar): resolve TypeScript error for locale.code access#10716

Open
okxint wants to merge 1 commit into
shadcn-ui:mainfrom
okxint:fix/calendar-locale-code-ts-error
Open

fix(calendar): resolve TypeScript error for locale.code access#10716
okxint wants to merge 1 commit into
shadcn-ui:mainfrom
okxint:fix/calendar-locale-code-ts-error

Conversation

@okxint
Copy link
Copy Markdown

@okxint okxint commented May 21, 2026

What

All base-* and radix-* calendar variants access locale?.code in two places:

  1. formatMonthDropdown formatter — date.toLocaleString(locale?.code, { month: "short" })
  2. data-day attribute — day.date.toLocaleDateString(locale?.code)

The Locale type re-exported from react-day-picker is typed as DayPickerLocale which does not declare a code property, causing a TypeScript error: Property 'code' does not exist on type 'DayPickerLocale'.

Fix

Add a minimal inline type assertion (locale as { code?: string }) at both call sites in all 16 affected files. The underlying date-fns Locale object does carry code at runtime — only the type was too narrow.

No behavior change.

Fixes #10709

DayPickerLocale does not expose a code property at the type level even
though the underlying date-fns Locale object carries one at runtime.
Add a minimal inline type assertion so TypeScript no longer errors when
reading locale?.code in formatMonthDropdown and data-day across all
base-* and radix-* calendar variants.

Fixes shadcn-ui#10709
@github-actions
Copy link
Copy Markdown
Contributor

Can you sign the commits please? See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits. Thank you.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 21, 2026

@okxint is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

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.

[bug]: Property 'code' does not exist on type 'DayPickerLocale'.ts(2339)

1 participant