Skip to content

Commit

Permalink
chore: fix broken types
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jul 5, 2024
1 parent 7423527 commit 722577b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
- run: pnpm lint
- run: pnpm test
- run: pnpm build
- run: pnpm test:types
- run: pnpm typecheck
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default defineNuxtModule<ModuleOptions>({
let types = `
declare module '#app' {
interface NuxtApp {
$scripts: Record<${[...Object.keys(config.globals || {}), ...Object.keys(config.registry || {})].map(k => `'${k}'`).join(' | ')}, Pick<(import('#nuxt-scripts').NuxtAppScript), '$script'> & Record<string, any>>
$scripts: Record<${[...Object.keys(config.globals || {}), ...Object.keys(config.registry || {})].map(k => `'${k}'`).concat(['string']).join(' | ')}, Pick<(import('#nuxt-scripts').NuxtAppScript), '$script'> & Record<string, any>>
_scripts: Record<string, (import('#nuxt-scripts').NuxtAppScript)>
}
interface RuntimeNuxtHooks {
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/composables/useScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function useScript<T extends Record<string | symbol, any>>(input: UseScri
const id = (input.key || input.src || hashCode((typeof input.innerHTML === 'string' ? input.innerHTML : ''))) as keyof typeof nuxtApp._scripts
nuxtApp.$scripts = nuxtApp.$scripts! || reactive({})
// return early
if (nuxtApp.$scripts[id]) {
return nuxtApp.$scripts[id]
if ((nuxtApp.$scripts as Record<string, any>)[id]) {
return (nuxtApp.$scripts as Record<string, any>)[id]
}
if (import.meta.client) {
// only validate if we're initializing the script
Expand All @@ -36,6 +36,7 @@ export function useScript<T extends Record<string | symbol, any>>(input: UseScri
}
}
const instance = _useScript<T>(input, options as any as UseScriptOptions<T>)
// @ts-expect-error untyped
nuxtApp.$scripts[id] = instance
// used for devtools integration
if (import.meta.dev && import.meta.client) {
Expand Down

0 comments on commit 722577b

Please sign in to comment.