|
1 | 1 | import { describe, expectTypeOf, it } from 'vitest' |
2 | 2 | import type { ModuleOptions } from '../../src/module' |
3 | | -import type { ScriptRegistry } from '../../src/runtime/types' |
| 3 | +import type { |
| 4 | + NuxtUseScriptOptions, |
| 5 | + RegistryScriptInput, |
| 6 | + ScriptRegistry, |
| 7 | + UseScriptContext, |
| 8 | +} from '../../src/runtime/types' |
4 | 9 |
|
5 | | -describe('module options registry', async () => { |
6 | | - it('expect no any', async () => { |
7 | | - expectTypeOf<NonNullable<NonNullable<ModuleOptions>['registry']>[keyof ScriptRegistry]>().not.toBeAny() |
| 10 | +describe('module options registry', () => { |
| 11 | + it('registry entries are typed', () => { |
| 12 | + // Check specific registry keys have proper types (not any) |
| 13 | + // Using specific keys because the index signature `[key: \`${string}-npm\`]` |
| 14 | + // causes `keyof ScriptRegistry` to include template literals which resolve to any |
| 15 | + type Registry = NonNullable<ModuleOptions['registry']> |
| 16 | + expectTypeOf<Registry['googleAnalytics']>().not.toBeAny() |
| 17 | + expectTypeOf<Registry['clarity']>().not.toBeAny() |
| 18 | + expectTypeOf<Registry['stripe']>().not.toBeAny() |
| 19 | + }) |
| 20 | +}) |
| 21 | + |
| 22 | +// Issue #570: Verify #nuxt-scripts/types exports are available |
| 23 | +// When adding new scripts to registry, the type definitions were broken |
| 24 | +// because `export {}` was missing from the generated .d.ts file |
| 25 | +describe('#nuxt-scripts/types exports', () => { |
| 26 | + it('exports UseScriptContext type', () => { |
| 27 | + expectTypeOf<UseScriptContext<{ foo: string }>>().not.toBeAny() |
| 28 | + expectTypeOf<UseScriptContext<{ foo: string }>>().toBeObject() |
| 29 | + }) |
| 30 | + |
| 31 | + it('exports NuxtUseScriptOptions type', () => { |
| 32 | + expectTypeOf<NuxtUseScriptOptions>().not.toBeAny() |
| 33 | + expectTypeOf<NuxtUseScriptOptions>().toBeObject() |
| 34 | + }) |
| 35 | + |
| 36 | + it('exports RegistryScriptInput type', () => { |
| 37 | + expectTypeOf<RegistryScriptInput>().not.toBeAny() |
| 38 | + }) |
| 39 | + |
| 40 | + it('exports ScriptRegistry interface', () => { |
| 41 | + expectTypeOf<ScriptRegistry>().not.toBeAny() |
| 42 | + expectTypeOf<ScriptRegistry>().toBeObject() |
| 43 | + }) |
| 44 | + |
| 45 | + it('ScriptRegistry has known keys', () => { |
| 46 | + expectTypeOf<ScriptRegistry>().toHaveProperty('googleAnalytics') |
| 47 | + expectTypeOf<ScriptRegistry>().toHaveProperty('googleTagManager') |
| 48 | + expectTypeOf<ScriptRegistry>().toHaveProperty('clarity') |
8 | 49 | }) |
9 | 50 | }) |
0 commit comments