Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

generate: Autoimported $fetch not type friendly #14677

Closed
some-user123 opened this issue Aug 23, 2022 · 5 comments
Closed

generate: Autoimported $fetch not type friendly #14677

some-user123 opened this issue Aug 23, 2022 · 5 comments

Comments

@some-user123
Copy link

some-user123 commented Aug 23, 2022

Environment


  • Operating System: Windows_NT
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.8
  • Package Manager: pnpm@7.8.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

interface Article {
  id: number
}
const article = await $fetch<Article>(`/api/article/42`)

Describe the bug

According to ohmyfetch docu $fetch accepts a type parameter.

Using it in nuxi generate with auto import yields a type error: Expected 0 type arguments, but got 1. (ts2558)

If explicitly imported (import { $fetch } from 'ohmyfetch') the type parameter is accepted.

Additional context

Bug occurs only when using nuxi generate!

Logs

No response

@some-user123 some-user123 reopened this Aug 23, 2022
@some-user123 some-user123 changed the title Autoimported $fetch not type friendly generate: Autoimported $fetch not type friendly Aug 23, 2022
@danielroe
Copy link
Member

Would you provide a reproduction? 🙏

@some-user123
Copy link
Author

Please find it here: https://github.com/some-user123/nuxt3-typecheck

$ pnpm generate; pnpm typecheck

...
> nuxt typecheck

Nuxt CLI v3.0.0-rc.8                                                                                                                           16:22:12
pages/index.vue:12:30 - error TS2558: Expected 0 type arguments, but got 1.

12 const article = await $fetch<Article>('https://jsonplaceholder.typicode.com/todos/1')
                                ~~~~~~~


Found 1 error in pages/index.vue:12
...

@danielroe
Copy link
Member

@some-user123
Copy link
Author

It happens if you run generate before typechecking:
image

@danielroe
Copy link
Member

This should have been resolved in nuxt/framework#8848.

See https://stackblitz.com/edit/github-hdikgx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants