@@ -6,6 +6,7 @@ import { parse } from '#nuxt-scripts-validator'
6
6
import { useRuntimeConfig } from '#imports'
7
7
import type {
8
8
EmptyOptionsSchema ,
9
+ InferIfSchema ,
9
10
NuxtUseScriptOptions ,
10
11
RegistryScriptInput ,
11
12
ScriptRegistry ,
@@ -27,21 +28,21 @@ function validateScriptInputSchema<T extends GenericSchema>(key: string, schema:
27
28
}
28
29
}
29
30
30
- type OptionsFn < O extends ObjectSchema < any , any > > = ( options : InferInput < O > ) => ( {
31
+ type OptionsFn < O > = ( options : InferIfSchema < O > ) => ( {
31
32
scriptInput ?: UseScriptInput
32
33
scriptOptions ?: NuxtUseScriptOptions
33
- schema ?: O
34
+ schema ?: O extends ObjectSchema < any , any > ? O : undefined
34
35
clientInit ?: ( ) => void
35
36
} )
36
37
37
38
export function scriptRuntimeConfig < T extends keyof ScriptRegistry > ( key : T ) {
38
39
return ( ( useRuntimeConfig ( ) . public . scripts || { } ) as ScriptRegistry ) [ key ]
39
40
}
40
41
41
- export function useRegistryScript < T extends Record < string | symbol , any > , O extends ObjectSchema < any , any > = EmptyOptionsSchema , U = { } > ( registryKey : keyof ScriptRegistry | string , optionsFn : OptionsFn < O > , _userOptions ?: RegistryScriptInput < O > ) {
42
+ export function useRegistryScript < T extends Record < string | symbol , any > , O = EmptyOptionsSchema , U = { } > ( registryKey : keyof ScriptRegistry | string , optionsFn : OptionsFn < O > , _userOptions ?: RegistryScriptInput < O > ) {
42
43
const scriptConfig = scriptRuntimeConfig ( registryKey as keyof ScriptRegistry )
43
44
const userOptions = Object . assign ( _userOptions || { } , typeof scriptConfig === 'object' ? scriptConfig : { } )
44
- const options = optionsFn ( userOptions )
45
+ const options = optionsFn ( userOptions as InferIfSchema < O > )
45
46
46
47
const scriptInput = defu ( userOptions . scriptInput , options . scriptInput , { key : registryKey } ) as any as UseScriptInput
47
48
const scriptOptions = Object . assign ( userOptions ?. scriptOptions || { } , options . scriptOptions || { } )
0 commit comments