1
1
import { defu } from 'defu'
2
- import type { BaseSchema , Input , ObjectSchema , ValiError } from 'valibot'
2
+ import type { GenericSchema , InferInput , ObjectSchema , ValiError } from 'valibot'
3
3
import type { UseScriptInput , VueScriptInstance } from '@unhead/vue'
4
4
import { parse } from '#nuxt-scripts-validator'
5
5
import { useRuntimeConfig , useScript } from '#imports'
@@ -10,20 +10,21 @@ import type {
10
10
ScriptRegistry ,
11
11
} from '#nuxt-scripts'
12
12
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 > ) {
14
14
if ( import . meta. dev ) {
15
15
try {
16
16
parse ( schema , options )
17
17
}
18
18
catch ( _e ) {
19
- const e = _e as ValiError
19
+ const e = _e as ValiError < any >
20
20
// TODO nicer error handling
21
+ // @ts -expect-error untyped?
21
22
console . error ( e . issues . map ( i => `${ key } .${ i . path ?. map ( i => i . key ) . join ( ',' ) } : ${ i . message } ` ) . join ( '\n' ) )
22
23
}
23
24
}
24
25
}
25
26
26
- type OptionsFn < O extends ObjectSchema < any > > = ( options : Input < O > ) => ( {
27
+ type OptionsFn < O extends ObjectSchema < any , any > > = ( options : InferInput < O > ) => ( {
27
28
scriptInput ?: UseScriptInput
28
29
scriptOptions ?: NuxtUseScriptOptions
29
30
schema ?: O
@@ -34,7 +35,7 @@ export function scriptRuntimeConfig<T extends keyof ScriptRegistry>(key: T) {
34
35
return ( ( useRuntimeConfig ( ) . public . scripts || { } ) as ScriptRegistry ) [ key ]
35
36
}
36
37
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 & {
38
39
$script : Promise < T > & VueScriptInstance < T >
39
40
} {
40
41
const scriptConfig = scriptRuntimeConfig ( key as keyof ScriptRegistry )
0 commit comments