Skip to content

Commit 6e8cbd2

Browse files
committed
chore: broken ts
1 parent 7b46151 commit 6e8cbd2

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

Diff for: src/plugins/transform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { SourceMapInput } from 'rollup'
66
import type { Node } from 'estree-walker'
77
import { walk } from 'estree-walker'
88
import type { Literal, ObjectExpression, Property, SimpleCallExpression } from 'estree'
9-
import type { Input } from 'valibot'
9+
import type { InferInput } from 'valibot'
1010
import type { RegistryScript } from '#nuxt-scripts'
1111

1212
export interface AssetBundlerTransformerOptions {
@@ -102,7 +102,7 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
102102
scriptSrcNode = srcProperty?.value as Literal & { start: number, end: number }
103103
}
104104
else {
105-
src = registryNode.scriptBundling && registryNode.scriptBundling(fnArg0 as any as Input<any>)
105+
src = registryNode.scriptBundling && registryNode.scriptBundling(fnArg0 as any as InferInput<any>)
106106
// not supported
107107
if (src === false)
108108
return

Diff for: src/runtime/registry/cloudflare-web-analytics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useRegistryScript } from '../utils'
2-
import { boolean, minLength, object, optional, string } from '#nuxt-scripts-validator'
2+
import { boolean, minLength, object, optional, pipe, string } from '#nuxt-scripts-validator'
33
import type { RegistryScriptInput } from '#nuxt-scripts'
44

55
/**
@@ -25,7 +25,7 @@ export const CloudflareWebAnalyticsOptions = object({
2525
/**
2626
* The Cloudflare Web Analytics token.
2727
*/
28-
token: string([minLength(32)]),
28+
token: pipe(string(), minLength(32)),
2929
/**
3030
* Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API’s pushState function
3131
* and listening to the onpopstate. Hash-based router is not supported.

Diff for: src/runtime/registry/intercom.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { joinURL } from 'ufo'
22
import { useRegistryScript } from '../utils'
3-
import { type Input, literal, number, object, optional, string, union } from '#nuxt-scripts-validator'
3+
import { type InferInput, literal, number, object, optional, string, union } from '#nuxt-scripts-validator'
44
import type { RegistryScriptInput } from '#nuxt-scripts'
55

66
export const IntercomOptions = object({
@@ -18,9 +18,9 @@ export const IntercomOptions = object({
1818
export type IntercomInput = RegistryScriptInput<typeof IntercomOptions>
1919

2020
export interface IntercomApi {
21-
Intercom: ((event: 'boot', data?: Input<typeof IntercomOptions>) => void)
21+
Intercom: ((event: 'boot', data?: InferInput<typeof IntercomOptions>) => void)
2222
& ((event: 'shutdown') => void)
23-
& ((event: 'update', options?: Input<typeof IntercomOptions>) => void)
23+
& ((event: 'update', options?: InferInput<typeof IntercomOptions>) => void)
2424
& ((event: 'hide') => void)
2525
& ((event: 'show') => void)
2626
& ((event: 'showSpace', spaceName: 'home' | 'messages' | 'help' | 'news' | 'tasks' | 'tickets' | string) => void)

Diff for: src/runtime/types.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { UseScriptOptions } from '@unhead/schema'
22
import type { UseScriptInput, VueScriptInstance } from '@unhead/vue'
33
import type { ComputedRef, Ref } from 'vue'
4-
import type { Input, ObjectSchema } from 'valibot'
4+
import type { InferInput, ObjectSchema } from 'valibot'
55
import type { Import } from 'unimport'
66
import { object } from 'valibot'
77
import type { SegmentInput } from './registry/segment'
@@ -19,8 +19,10 @@ import type { YouTubePlayerInput } from './registry/youtube-player'
1919
import type { PlausibleAnalyticsInput } from './registry/plausible-analytics'
2020
import type { NpmInput } from './registry/npm'
2121
import type { LemonSqueezyInput } from './registry/lemon-squeezy'
22-
import type { Input as GoogleTagManagerInput } from '#build/nuxt-scripts/tpc/google-tag-manager'
23-
import type { Input as GoogleAnalyticsInput } from '#build/nuxt-scripts/tpc/google-analytics'
22+
// @ts-expect-error build-time
23+
import type { InferInput as GoogleTagManagerInput } from '#build/nuxt-scripts/tpc/google-tag-manager'
24+
// @ts-expect-error build-time
25+
import type { InferInput as GoogleAnalyticsInput } from '#build/nuxt-scripts/tpc/google-analytics'
2426

2527
export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
2628
/**
@@ -110,7 +112,7 @@ const emptyOptions = object({})
110112

111113
export type EmptyOptionsSchema = typeof emptyOptions
112114

113-
export type RegistryScriptInput<T extends ObjectSchema<any> = EmptyOptionsSchema, Bundelable extends boolean = true> = Input<T> & {
115+
export type RegistryScriptInput<T extends ObjectSchema<any, any> = EmptyOptionsSchema, Bundelable extends boolean = true> = InferInput<T> & {
114116
scriptInput?: UseScriptInput
115117
scriptOptions?: Bundelable extends true ? Omit<NuxtUseScriptOptions, 'use'> : Omit<NuxtUseScriptOptions, 'bundle' | 'use'>
116118
}

Diff for: src/runtime/utils.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defu } from 'defu'
2-
import type { BaseSchema, Input, ObjectSchema, ValiError } from 'valibot'
2+
import type { GenericSchema, InferInput, ObjectSchema, ValiError} from 'valibot'
33
import type { UseScriptInput, VueScriptInstance } from '@unhead/vue'
44
import { parse } from '#nuxt-scripts-validator'
55
import { 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

Comments
 (0)