Is `HeadersInit` expected when using `fetch`? (v13.4.13)
Unanswered
Milkfish posted this in #help-forum
MilkfishOP
Looking at a really basic example for a Route Handler with the App Router, I get the following error (screenshot attached).
This example is took directly from the Next.js docs.
I understand that I can create my own headers (via
I'm just wondering why there is a mismatch between what is shown in the docs and what the types expect? Which is correct?
This example is took directly from the Next.js docs.
I understand that I can create my own headers (via
new Headers()).I'm just wondering why there is a mismatch between what is shown in the docs and what the types expect? Which is correct?
2 Replies
you can't assign an
undefined value to the header values. check the type of the variable being assigned to the API-Key header, it is string | undefined which is causing the errorMilkfishOP
I understand, just wondering because this is just copy-pasted from the docs - nearly every example in the docs that is using
headers has this problem of using some header field with undefined/null values. So when you copy-paste them, you will get an error.