Skip to content

fix: allow custom script keys in ScriptRegistry type#632

Merged
harlan-zw merged 2 commits intomainfrom
fix/581-custom-script-types
Mar 6, 2026
Merged

fix: allow custom script keys in ScriptRegistry type#632
harlan-zw merged 2 commits intomainfrom
fix/581-custom-script-types

Conversation

@harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Mar 6, 2026

🔗 Linked issue

Resolves #581

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Custom scripts registered via the scripts:registry hook caused TypeScript errors in nuxt.config because ScriptRegistry only contained built-in keys. Adds Record<string & {}, any> intersection to NuxtConfigScriptRegistry (not ScriptRegistry itself, which would break keyof) so custom script keys are accepted while preserving autocomplete for built-in scripts.

Adds a string index signature to `ScriptRegistry` so custom scripts
registered via `scripts:registry` hook are accepted in nuxt.config.

Closes #581
@vercel
Copy link
Contributor

vercel bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
scripts-playground Ready Ready Preview, Comment Mar 6, 2026 3:58am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@632

commit: a59cd3a

@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eeb90225-f83d-4f1c-aeb1-bea1fd987f88

📥 Commits

Reviewing files that changed from the base of the PR and between f6c2c6f and 101da2f.

📒 Files selected for processing (1)
  • src/runtime/types.ts

📝 Walkthrough

Walkthrough

In src/runtime/types.ts the exported type NuxtConfigScriptRegistry<T extends keyof ScriptRegistry = keyof ScriptRegistry> was changed from Partial<{ [key in T]: NuxtConfigScriptRegistryEntry<ScriptRegistry[key]> }> to Partial<{ [key in T]: NuxtConfigScriptRegistryEntry<ScriptRegistry[key]> }> & Record<string & {}, NuxtConfigScriptRegistryEntry<any>>. This adds a public index signature allowing arbitrary string keys to map to NuxtConfigScriptRegistryEntry<any> while keeping the existing explicitly-typed entries.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: allow custom script keys in ScriptRegistry type' is specific and directly reflects the main change—enabling custom script keys in the type definition.
Description check ✅ Passed The description includes a summary, linked issue reference (Closes #581), and test plan, covering the main objectives. Type of change checkbox is unchecked but the summary clearly indicates this is a bug fix.
Linked Issues check ✅ Passed The PR successfully addresses issue #581 by adding an index signature to allow custom script keys in ScriptRegistry while preserving autocomplete for built-in scripts, matching all stated objectives.
Out of Scope Changes check ✅ Passed The change is narrowly focused on the NuxtConfigScriptRegistry type definition to support custom keys, with no unrelated modifications detected in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/581-custom-script-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

The index signature on ScriptRegistry broke `keyof ScriptRegistry`
(returns `string | number` instead of `string`). Instead, add the
`Record<string & {}, any>` intersection to NuxtConfigScriptRegistry
which is used for nuxt.config validation only.
@harlan-zw harlan-zw merged commit 00fbaae into main Mar 6, 2026
9 checks passed
@harlan-zw harlan-zw deleted the fix/581-custom-script-types branch March 6, 2026 05:02
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.

Add type support for custom scripts configuration in nuxt.config

1 participant