fix(i18n): allow getLocaleDir fallback to compile under TypeScript 6#3824
fix(i18n): allow getLocaleDir fallback to compile under TypeScript 6#3824SAY-5 wants to merge 1 commit intowithastro:mainfrom
Conversation
🦋 Changeset detectedLatest commit: c78f12d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hello! Thank you for opening your first PR to Starlight! ✨ Here’s what will happen next:
|
There was a problem hiding this comment.
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).
|
Thanks @delucis! Switched to |
|
@SAY-5 Looks like the lint job is still failing. You can see how we ignore this lint rule for You can run |
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]>
8ddf6aa to
c78f12d
Compare

Per #3822, after upgrading to TypeScript v6 (which ships a newer DOM lib that knows about both
Intl.Locale.textInfoandIntl.Locale.getTextInfo),tsc --noEmitfails with:The two
ifbranches ingetLocaleDirnarrowlocaletoneverbecause TypeScript now sees both branches as exhaustive, which leaves the fallback unreachable from a type-narrowing standpoint.Cast
localeback toIntl.Localein 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