-
Notifications
You must be signed in to change notification settings - Fork 92
fix(types): broken IDE display of registry types #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,9 +252,25 @@ export type RegistryScriptKey = Exclude<keyof ScriptRegistry, `${string}-npm`> | |
| type RegistryConfigInput<T> = [T] extends [true] ? Record<string, never> : T | ||
|
|
||
| export type NuxtConfigScriptRegistryEntry<T> = true | false | 'mock' | (RegistryConfigInput<T> & { trigger?: NuxtUseScriptOptionsSerializable['trigger'] | false, proxy?: boolean, bundle?: boolean, partytown?: boolean, privacy?: ProxyPrivacyInput }) | ||
| export type NuxtConfigScriptRegistry<T extends keyof ScriptRegistry = keyof ScriptRegistry> = Partial<{ | ||
| [key in T]: NuxtConfigScriptRegistryEntry<ScriptRegistry[key]> | ||
| }> & Record<string & {}, NuxtConfigScriptRegistryEntry<any>> | ||
|
|
||
| // Internal mapped type: derives config entry types from ScriptRegistry. | ||
| // Excludes the `${string}-npm` pattern since it's covered by the string index signature. | ||
| type _NuxtConfigScriptRegistryEntries = { | ||
| [K in keyof ScriptRegistry as K extends `${string}-npm` ? never : K]?: NuxtConfigScriptRegistryEntry<ScriptRegistry[K]> | ||
| } | ||
|
|
||
| // Interface (not intersection) ensures IDE displays specific types for known keys. | ||
| // Explicit properties inherited via `extends` always take priority over the index | ||
| // signature, making this immune to catch-all type contamination. | ||
| // Augmenting ScriptRegistry automatically flows through to this type. | ||
| // | ||
| // The index signature uses `any` to satisfy TypeScript's constraint that all | ||
| // inherited properties must be subtypes of the index type. This is safe because | ||
| // in an interface, explicit properties always take priority over the index | ||
| // signature for property access. | ||
| export interface NuxtConfigScriptRegistry extends _NuxtConfigScriptRegistryEntries { | ||
| [key: string]: any | ||
| } | ||
|
Comment on lines
+271
to
+273
|
||
|
|
||
| export type UseFunctionType<T, U> = T extends { | ||
| use: infer V | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excluding the
${string}-npmkeys from_NuxtConfigScriptRegistryEntriesmeans config entries likeregistry['foo-npm']now fall back to the[key: string]: anysignature and lose theirNpmInput-derived typing. If the intent is to keep npm pattern keys strongly typed, add an explicit${string}-npmindex signature (or include that pattern in the mapped type) withNuxtConfigScriptRegistryEntry<NpmInput>so it doesnβt collapse toany.