Skip to content

fix(optimize-locales-plugin): type Turbopack loader locales as a mutable array - #10889

Open
costajohnt wants to merge 1 commit into
adobe:mainfrom
costajohnt:fix/optimize-locales-turbopack-mutable-locales
Open

costajohnt wants to merge 1 commit into
adobe:mainfrom
costajohnt:fix/optimize-locales-turbopack-mutable-locales

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Closes #10880

optimizeLocales.turbopack() declares each loader's options as {locales: readonly string[]}. Next's TurbopackLoaderOptions is Record<string, JSONValue>, and JSONValue[] is a mutable array, so spreading the returned rules into a typed NextConfig fails with TS2322 even though the rule works at runtime. This changes the declared loader option to string[], which is the change suggested in the issue. The Options input type stays readonly string[], so callers can still pass as const arrays. Only the shape handed to Next changes.

I checked it against next@16.4.2 and TypeScript 6.0.3 (strict) with a next.config.ts covering a single config, a conditioned list, a readonly as const locales array, and a path/content RegExp condition. With the current declaration all four report TS2322 (The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'JSONValue[]'). With this change tsc --noEmit passes.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices
  • I understand every change in this PR and can explain why it's there.
  • If AI-assisted, I followed our AI contribution guidance and pointed my assistant at AGENTS.md.

Type-only change to a .d.ts, so no unit test, docs or a11y change applies. The plugin directory is excluded from yarn check-types, so the verification is the standalone check below. Drafted with Claude Code; I reviewed the change and the verification myself.

📝 Test Instructions:

  1. In a scratch project, install next@16.4.2 and typescript@6, and copy this package's LocalesPlugin.d.ts and package.json into node_modules/@react-aria/optimize-locales-plugin/.
  2. Add the next.config.ts from optimize-locales-plugin: turbopack() rules are refused by Next 16.4's NextConfig type (readonly locales) #10880:
    import optimizeLocales from "@react-aria/optimize-locales-plugin";
    import type { NextConfig } from "next";
    
    const nextConfig: NextConfig = {
      turbopack: {
        rules: {
          ...optimizeLocales.turbopack({ locales: ["de-DE"] }).rules,
        },
      },
    };
    
    export default nextConfig;
  3. Run npx tsc --noEmit --strict. It reports TS2322 on main and passes with this branch.

🧢 Your Project:

Personal

…ble array

Next's TurbopackLoaderOptions only accepts mutable JSONValue arrays, so the
readonly locales type made optimizeLocales.turbopack() rules fail to
type-check in a NextConfig.
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.

optimize-locales-plugin: turbopack() rules are refused by Next 16.4's NextConfig type (readonly locales)

2 participants