Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Type definitions are incorrect when importing useAsyncData from #imports #233

Closed
cjpearson opened this issue Mar 8, 2024 · 1 comment
Closed

Comments

@cjpearson
Copy link

Environment


  • Operating System: Darwin
  • Node Version: v20.9.0
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.9.1
  • Package Manager: yarn@1.22.19
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

The issue can be reproduced by adding this sample composable to the starter nuxt module. e.g. npx nuxi init -t module quick-test

src/runtime/composables/useHelloWorld.ts

import { useAsyncData } from '#imports'

export async function useHelloWorld() {
  const {
    data,
  } = await useAsyncData(
    'use-hello-world',
    () => Promise.resolve({ hello: 'world'}),
  )

  return {
    data,
  }
}

Run yarn nuxt-module-build build && cat dist/runtime/composables/useHelloWorld.d.ts which produces the following output:

export declare function useHelloWorld(): Promise<{
    data: any;
}>;

If the import is changed to use nuxt/app, the output is correct:

export declare function useHelloWorld(): Promise<{
    data: import("vue").Ref<{
        hello: string;
    } | null>;
}>;

Describe the bug

When using useAsyncData inside a module, the compiled type definitions are incorrect if useAsyncData is imported from #imports. Changing the import to import { useAsyncData } from 'nuxt/app' resolves the issue, but my understanding is that '#imports' is preferred.

Additional context

No response

Logs

No response

@danielroe danielroe transferred this issue from nuxt/nuxt Mar 9, 2024
@danielroe
Copy link
Member

Resolved in #255.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants