Skip to content

Type wrong: default option of useFetch  #14437

Description

@aaharu

Environment

  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.6
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: typescript
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-z9sira?file=app.vue

Describe the bug

When the type has be changed by useFetch's transform, default's return type should be its after transformed.

https://github.com/nuxt/framework/blob/v3.0.0-rc.6/packages/nuxt/src/app/composables/fetch.ts#L26

app.vue:29:20 - error TS2322: Type 'string[]' is not assignable to type 'Sample | Ref<Sample>'.

29     default: () => ['Unknown'],
                      ~~~~~~~~~~~

  node_modules/nuxt/dist/app/composables/asyncData.d.ts:11:15
    11     default?: () => DataT | Ref<DataT>;
                     ~~~~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from the return type of this signature.


Found 1 error in app.vue:29


 ERROR  Command failed with exit code 2: vue-tsc --noEmit               00:51:48

  at makeError (node_modules/nuxi/dist/chunks/index5.mjs:1257:11)
  at handlePromise (node_modules/nuxi/dist/chunks/index5.mjs:2086:35)
  at <anonymous> (<anonymous>)

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions