From f17d33e4ad1bb15e727a3d472c76bda295b7b0ef Mon Sep 17 00:00:00 2001 From: harlan Date: Tue, 21 Jan 2025 14:34:21 +1100 Subject: [PATCH] chore(scripts): export `UseScriptReturn` --- packages/scripts/src/types.ts | 2 ++ packages/scripts/src/useScript.ts | 3 ++- packages/scripts/src/vue/useScript.ts | 14 ++++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/scripts/src/types.ts b/packages/scripts/src/types.ts index ee2285fb..a647a248 100644 --- a/packages/scripts/src/types.ts +++ b/packages/scripts/src/types.ts @@ -106,3 +106,5 @@ export interface UseScriptOptions> */ beforeInit?: () => void } + +export type UseScriptReturn> = UseScriptContext, T>> diff --git a/packages/scripts/src/useScript.ts b/packages/scripts/src/useScript.ts index 647ffd6d..150b53b4 100644 --- a/packages/scripts/src/useScript.ts +++ b/packages/scripts/src/useScript.ts @@ -10,6 +10,7 @@ import type { UseScriptInput, UseScriptOptions, UseScriptResolvedInput, + UseScriptReturn, WarmupStrategy, } from './types' import { hashCode, ScriptNetworkEvents } from '@unhead/shared' @@ -26,7 +27,7 @@ const PreconnectServerModes = ['preconnect', 'dns-prefetch'] * * @see https://unhead.unjs.io/usage/composables/use-script */ -export function useScript = Record>(head: Unhead, _input: UseScriptInput, _options?: UseScriptOptions): UseScriptContext, T>> { +export function useScript = Record>(head: Unhead, _input: UseScriptInput, _options?: UseScriptOptions): UseScriptReturn { const input: UseScriptResolvedInput = typeof _input === 'string' ? { src: _input } : _input const options = _options || {} const id = resolveScriptKey(input) diff --git a/packages/scripts/src/vue/useScript.ts b/packages/scripts/src/vue/useScript.ts index a331b61f..7772bc84 100644 --- a/packages/scripts/src/vue/useScript.ts +++ b/packages/scripts/src/vue/useScript.ts @@ -4,7 +4,7 @@ import type { SchemaAugmentations, ScriptBase, } from '@unhead/schema' -import type { MaybeComputedRefEntriesOnly } from '@unhead/vue' +import type { MaybeComputedRefEntriesOnly, VueHeadClient } from '@unhead/vue' import type { ComponentInternalInstance, Ref, WatchHandle } from 'vue' import type { UseScriptOptions as BaseUseScriptOptions, ScriptInstance, UseFunctionType, UseScriptStatus } from '../types' import { injectHead } from '@unhead/vue' @@ -16,7 +16,7 @@ export interface VueScriptInstance> exten } export type UseScriptInput = string | (MaybeComputedRefEntriesOnly> & { src: string }) -export interface UseScriptOptions = Record> extends HeadEntryOptions, Pick, 'use' | 'eventContext' | 'beforeInit'> { +export interface UseScriptOptions = Record> extends Omit, Pick, 'use' | 'eventContext' | 'beforeInit'> { /** * The trigger to load the script: * - `undefined` | `client` - (Default) Load the script on the client when this js is loaded. @@ -27,6 +27,10 @@ export interface UseScriptOptions = Recor * - `ref` - Load the script when the ref is true. */ trigger?: BaseUseScriptOptions['trigger'] | Ref + /** + * Unhead instance. + */ + head?: VueHeadClient } export type UseScriptContext> = Promise & VueScriptInstance @@ -60,7 +64,9 @@ function registerVueScopeHandlers = Recor }) } -export function useScript = Record>(_input: UseScriptInput, _options?: UseScriptOptions): UseScriptContext, T>> { +export type UseScriptReturn> = UseScriptContext, T>> + +export function useScript = Record>(_input: UseScriptInput, _options?: UseScriptOptions): UseScriptReturn { const input = (typeof _input === 'string' ? { src: _input } : _input) as UseScriptInput const options = _options || {} as UseScriptOptions const head = options?.head || injectHead() @@ -105,5 +111,5 @@ export function useScript = Record, T>> + }) as any as UseScriptReturn }