11import { defu } from 'defu'
2- import type { BaseSchema , Input , ObjectSchema , ValiError } from 'valibot'
2+ import type { GenericSchema , InferInput , ObjectSchema , ValiError } from 'valibot'
33import type { UseScriptInput , VueScriptInstance } from '@unhead/vue'
44import { parse } from '#nuxt-scripts-validator'
55import { useRuntimeConfig , useScript } from '#imports'
@@ -10,20 +10,21 @@ import type {
1010 ScriptRegistry ,
1111} from '#nuxt-scripts'
1212
13- function validateScriptInputSchema < T extends BaseSchema < any > > ( key : string , schema : T , options ?: Input < T > ) {
13+ function validateScriptInputSchema < T extends GenericSchema > ( key : string , schema : T , options ?: InferInput < T > ) {
1414 if ( import . meta. dev ) {
1515 try {
1616 parse ( schema , options )
1717 }
1818 catch ( _e ) {
19- const e = _e as ValiError
19+ const e = _e as ValiError < any >
2020 // TODO nicer error handling
21+ // @ts -expect-error untyped?
2122 console . error ( e . issues . map ( i => `${ key } .${ i . path ?. map ( i => i . key ) . join ( ',' ) } : ${ i . message } ` ) . join ( '\n' ) )
2223 }
2324 }
2425}
2526
26- type OptionsFn < O extends ObjectSchema < any > > = ( options : Input < O > ) => ( {
27+ type OptionsFn < O extends ObjectSchema < any , any > > = ( options : InferInput < O > ) => ( {
2728 scriptInput ?: UseScriptInput
2829 scriptOptions ?: NuxtUseScriptOptions
2930 schema ?: O
@@ -34,7 +35,7 @@ export function scriptRuntimeConfig<T extends keyof ScriptRegistry>(key: T) {
3435 return ( ( useRuntimeConfig ( ) . public . scripts || { } ) as ScriptRegistry ) [ key ]
3536}
3637
37- export function useRegistryScript < T extends Record < string | symbol , any > , O extends ObjectSchema < any > = EmptyOptionsSchema > ( key : keyof ScriptRegistry | string , optionsFn : OptionsFn < O > , _userOptions ?: RegistryScriptInput < O > ) : T & {
38+ export function useRegistryScript < T extends Record < string | symbol , any > , O extends ObjectSchema < any , any > = EmptyOptionsSchema > ( key : keyof ScriptRegistry | string , optionsFn : OptionsFn < O > , _userOptions ?: RegistryScriptInput < O > ) : T & {
3839 $script : Promise < T > & VueScriptInstance < T >
3940} {
4041 const scriptConfig = scriptRuntimeConfig ( key as keyof ScriptRegistry )
0 commit comments