`useFetch()`TS error when using `useRequestHeader()`
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v16.16.0
- Nuxt Version:
3.0.0-rc.10
- Nitro Version:
0.5.3
- Package Manager:
yarn@1.22.19
- Builder:
vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
I tried to reproduce in stackblitz but didnt get any TS errors so not sure if its an environment thing. I did spin up a completely clean app with nuxi init
and the error was there.
<template>
<div>
{{ items }}
</div>
</template>
<script setup lang="ts">
useHead({
title: "Items",
});
const { data: items } = await useFetch("/api/items", {
headers: useRequestHeaders(["cookie"]),
});
</script>
Describe the bug
TS error on the header field of userFetch()
Argument of type '{ headers: Record<"cookie", string>; }' is not assignable to parameter of type 'UseFetchOptions<unknown, (res: unknown) => unknown, KeyOfRes<(res: unknown) => unknown>>'.
Object literal may only specify known properties, but 'headers' does not exist in type 'UseFetchOptions<unknown, (res: unknown) => unknown, KeyOfRes<(res: unknown) => unknown>>'. Did you mean to write 'aheaders'?ts(2345)
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
useFetch.ts hook react test mock - Stack Overflow
It says, displays (in the test screen.debug()) the "Error" if statement, and even when I left out form the component the if error...
Read more >Data Fetching · Get Started with Nuxt
The key to making this work is to call the refresh() method returned from the useFetch() composable when a query parameter has changed....
Read more >useFetch() react hook - usehooks-ts
useFetch(). Here is a React Hook which aims to retrieve data on an API using the native Fetch API. I used a reducer...
Read more >useFetch
You can do that too var { request, response, // Do not destructure the `response` object! loading, error, data, cache, // .has(), .clear(),...
Read more >Error Handling - 《Nuxt 3 beta Documentation》 - 书栈网
Example with global error reporting framework ... or (on server side) directly within middleware, plugins or setup() functions.
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
This appears to be an issue related to this change https://github.com/nuxt/framework/pull/5748
The
useRequestHeaders
composable was changed to allow for headers not being found and returningundefined
All the fetch composables have the type definition of
headers
set toRecord<string, string>
so the current return type ofRecord<string, string | undefined>
fromuseRequestHeaders
is incompatible.A simple workaround for now is to
as Record<string, string>
the result ofuseRequestHeaders
.It is being caused by some external factor. Not sure what yet, or even how… but I will need to add in things bit by bit to see what is causing the issue