1- // @ts -expect-error untyped
21import type { UseScriptInput , UseScriptOptions , VueScriptInstance } from '@unhead/vue/scripts'
32import { defu } from 'defu'
4- // @ts -expect-error untyped
53import { useScript as _useScript } from '@unhead/vue/scripts'
64import { reactive } from 'vue'
75import type { NuxtDevToolsScriptInstance , NuxtUseScriptOptions , UseScriptContext } from '../types'
@@ -21,9 +19,9 @@ export function resolveScriptKey(input: any): string {
2119 return input . key || input . src || ( typeof input . innerHTML === 'string' ? input . innerHTML : '' )
2220}
2321
24- export function useScript < T extends Record < symbol | string , any > = Record < symbol | string , any > , U = Record < symbol | string , any > > ( input : UseScriptInput , options ?: NuxtUseScriptOptions < T , U > ) : UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T , U > , T > > {
22+ export function useScript < T extends Record < symbol | string , any > = Record < symbol | string , any > > ( input : UseScriptInput , options ?: NuxtUseScriptOptions < T > ) : UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T > , T > > {
2523 input = typeof input === 'string' ? { src : input } : input
26- options = defu ( options , useNuxtScriptRuntimeConfig ( ) ?. defaultScriptOptions ) as NuxtUseScriptOptions < T , U >
24+ options = defu ( options , useNuxtScriptRuntimeConfig ( ) ?. defaultScriptOptions ) as NuxtUseScriptOptions < T >
2725 // browser hint optimizations
2826 const id = String ( resolveScriptKey ( input ) as keyof typeof nuxtApp . _scripts )
2927 const nuxtApp = useNuxtApp ( )
@@ -40,7 +38,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
4038 }
4139 }
4240
43- const instance = _useScript < T > ( input , options as any as UseScriptOptions < T > ) as UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T , U > , T > >
41+ const instance = _useScript < T > ( input , options as any as UseScriptOptions < T > ) as UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T > , T > >
4442 const _remove = instance . remove
4543 instance . remove = ( ) => {
4644 nuxtApp . $scripts [ id ] = undefined
@@ -50,7 +48,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
5048 // used for devtools integration
5149 if ( import . meta. dev && import . meta. client ) {
5250 if ( exists ) {
53- return instance as any as UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T , U > , T > >
51+ return instance as any as UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T > , T > >
5452 }
5553 // sync scripts to nuxtApp with debug details
5654 const payload : NuxtDevToolsScriptInstance = {
@@ -67,6 +65,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
6765 }
6866
6967 if ( ! nuxtApp . _scripts [ instance . id ] ) {
68+ // @ts -expect-error untyped
7069 head . hooks . hook ( 'script:updated' , ( ctx ) => {
7170 if ( ctx . script . id !== instance . id )
7271 return
@@ -79,6 +78,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
7978 payload . $script = instance
8079 syncScripts ( )
8180 } )
81+ // @ts -expect-error untyped
8282 head . hooks . hook ( 'script:instance-fn' , ( ctx ) => {
8383 if ( ctx . script . id !== instance . id || String ( ctx . fn ) . startsWith ( '__v_' ) )
8484 return
@@ -100,5 +100,5 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
100100 syncScripts ( )
101101 }
102102 }
103- return instance as any as UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T , U > , T > >
103+ return instance as any as UseScriptContext < UseFunctionType < NuxtUseScriptOptions < T > , T > >
104104}
0 commit comments