Skip to content

fix(i18n): allow getLocaleDir fallback to compile under TypeScript 6#3824

Closed
SAY-5 wants to merge 1 commit intowithastro:mainfrom
SAY-5:fix/i18n-locale-language-ts6
Closed

fix(i18n): allow getLocaleDir fallback to compile under TypeScript 6#3824
SAY-5 wants to merge 1 commit intowithastro:mainfrom
SAY-5:fix/i18n-locale-language-ts6

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 15, 2026

Per #3822, after upgrading to TypeScript v6 (which ships a newer DOM lib that knows about both Intl.Locale.textInfo and Intl.Locale.getTextInfo), tsc --noEmit fails with:

Property 'language' does not exist on type 'never'.

The two if branches in getLocaleDir narrow locale to never because TypeScript now sees both branches as exhaustive, which leaves the fallback unreachable from a type-narrowing standpoint.

Cast locale back to Intl.Locale in the fallback so the runtime path (Firefox before either property is supported) still compiles. Runtime behaviour is unchanged. The longer-term cleanup tracked in #3572 is still the right path; this is the small forward fix users need today.

Closes #3822

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: c78f12d

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

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight 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

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 15, 2026

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit c78f12d
🔍 Latest deploy log https://app.netlify.com/projects/astro-starlight/deploys/69e99d3ed2111c00081e75bd
😎 Deploy Preview https://deploy-preview-3824--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the 🌟 core Changes to Starlight’s main package label Apr 15, 2026
@astrobot-houston
Copy link
Copy Markdown
Contributor

Hello! Thank you for opening your first PR to Starlight! ✨

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any issues you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Netlify 🤩

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @SAY-5! Looks like there’s a lint error due to the “unnecessary” as (from TypeScript v5’s perspective). Could you take a look?

To ensure compatibility across users with both TS 5 and TS 6, it might be better to use a // @ts-ignore comment instead of type casting in this case. We do that in a few other places in the code base where there’s TS code that can error is some projects but not in others (so we can’t use // @ts-expect-error).

@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented Apr 21, 2026

Thanks @delucis! Switched to @ts-ignore on the property access and dropped the cast. That keeps TS 5 happy (no unnecessary-cast lint) and TS 6 happy (narrowed type no longer carries language, directive silences it). The runtime property is always present because the in guards above only narrow statically.

@delucis
Copy link
Copy Markdown
Member

delucis commented Apr 22, 2026

@SAY-5 Looks like the lint job is still failing. You can see how we ignore this lint rule for @ts-ignore elsewhere in the codebase — I’d suggest doing the same here.

You can run pnpm lint locally to double check these kinds of things.

Switch from `(locale as Intl.Locale).language` to a plain property
access with a `@ts-ignore` directive. Per @delucis' review, the cast
lints as "unnecessary" under TypeScript v5, while the property is
reachable at runtime and only missing from the TypeScript v6 narrowed
type. `@ts-ignore` keeps both compilers happy without lint noise.

Signed-off-by: SAY-5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 core Changes to Starlight’s main package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript v6: Property 'language' does not exist on type 'never'

3 participants