Unverified Commit 3f75ff69 authored by RobertFent's avatar RobertFent Committed by GitHub

Use Array.from to avoid @ts-ignore when copying i18n.locales (#82148)

### What?
Replaces:
```ts
// @ts-ignore locales are readonly
const locales: string[] = i18n.locales;
```
with:
```ts
const locales = Array.from(i18n.locales);
```

### Why?
Avoids suppressing TypeScript errors via @ts-ignore.
Array.from safely creates a mutable copy without modifying the readonly
original, making the code cleaner and more type-safe.

### How?
Used Array.from(i18n.locales) instead of a forced type assertion.<br>

<br>
No functional change, purely a lint-/type-safety improvement.
Co-authored-by: 's avatarJoseph <joseph.chamochumbi@vercel.com>
parent c1967707
...@@ -11,8 +11,7 @@ function getLocale(request: NextRequest): string | undefined { ...@@ -11,8 +11,7 @@ function getLocale(request: NextRequest): string | undefined {
const negotiatorHeaders: Record<string, string> = {}; const negotiatorHeaders: Record<string, string> = {};
request.headers.forEach((value, key) => (negotiatorHeaders[key] = value)); request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));
// @ts-ignore locales are readonly const locales = Array.from(i18n.locales);
const locales: string[] = i18n.locales;
// Use negotiator and intl-localematcher to get best locale // Use negotiator and intl-localematcher to get best locale
let languages = new Negotiator({ headers: negotiatorHeaders }).languages( let languages = new Negotiator({ headers: negotiatorHeaders }).languages(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment