Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/script/src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export type BuiltInRegistryScriptKey
*/
export type RegistryScriptKey = Exclude<keyof ScriptRegistry, `${string}-npm`>

type RegistryConfigInput<T> = [T] extends [true] ? Record<string, never> : T
type RegistryConfigInput<T> = 0 extends 1 & T ? Record<string, any> : [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 })

Expand Down
19 changes: 12 additions & 7 deletions test/types/types.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import type { ModuleOptions } from '../../packages/script/src/module'
import type { CrispApi } from '../../packages/script/src/runtime/registry/crisp'
import type { DefaultEventName } from '../../packages/script/src/runtime/registry/google-analytics'
import type {
NuxtConfigScriptRegistry,
NuxtUseScriptOptions,
RegistryScriptInput,
ScriptRegistry,
UseScriptContext,
} from '../../packages/script/src/runtime/types'
import type { NuxtConfigScriptRegistry, NuxtConfigScriptRegistryEntry, NuxtUseScriptOptions, RegistryScriptInput, ScriptRegistry, UseScriptContext } from '../../packages/script/src/runtime/types'
import { describe, expectTypeOf, it } from 'vitest'

describe('module options registry', () => {
Expand Down Expand Up @@ -78,6 +72,17 @@ describe('module options registry', () => {
// Unknown keys fall through to the index signature (any), so custom scripts work
expectTypeOf<Registry['my-custom-script']>().toBeAny()
})

// Issue #700: NuxtConfigScriptRegistryEntry<any> must not collapse to Record<string, never>
// This happens when Nuxt's $production/$development wraps the config in DeepPartial,
// collapsing the interface's index signature priority and resolving all keys to `any`.
it('NuxtConfigScriptRegistryEntry<any> allows arbitrary properties', () => {
type Entry = Exclude<NuxtConfigScriptRegistryEntry<any>, boolean | 'mock'>
// Must not be never (would mean Record<string, never> killed the intersection)
expectTypeOf<Entry>().not.toBeNever()
// Arbitrary properties must be assignable, not `never`
expectTypeOf<{ matomoUrl: string, siteId: number }>().toMatchTypeOf<Entry>()
})
})

describe('registry api types', () => {
Expand Down
Loading