`useFetch` type return
See original GitHub issueEnvironment
- Operating System:
Windows_NT
- Node Version:
v16.13.1
- Nuxt Version:
3.0.0-27415326.3c563fa
- Package Manager:
yarn@1.22.17
- Bundler:
Vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
I use Visual Studio Code with Volar
Reproduction
In app.vue
, I fetch data with useFetch()
<script setup lang="ts">
interface Book {
title: string
authors: string[]
serie?: string
}
const { data } = await useFetch<Book>('/books?per-page=32', {
baseURL: 'https://bookshelves.ink/api',
lazy: true,
})
console.log(data.value)
</script>
CodeSandbox is available.
Describe the bug
When I want to add type to useFetch()
, I’ve an error
Type ‘Book’ does not satisfy the constraint ‘string’.
<script setup lang="ts">
const { data } = await useFetch<Book>('/books?per-page=32', {
baseURL: 'https://bookshelves.ink/api',
lazy: true,
})
</script>
It works with useAsyncData()
Additional context
Logs
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to specify useFetch data return type in Nuxt
I am using typescript and I wish to define the type of data that I will get. How do I specify this? <script...
Read more >useFetch() react hook - usehooks-ts
Here is a React Hook which aims to retrieve data on an API using the native Fetch API. I used a reducer to...
Read more >useFetch - VueUse
Setting the request method and return type #. The request method and return type can be set by adding the appropriate methods to...
Read more >useFetch - Raycast API
useFetch. Hook which fetches the URL and returns the AsyncState ... By default, the hook will return response.json() if the response has a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
let’s leave it open as a documentation issue
You can update it like this:
(The first generic is the type of the URL - it can either be a string or a typed string associated with a particular return type …)
Would be nice to document this.