Can you extend H3EventContext?
I'm trying to type my context correctly so it can be used inside defineEventHandler() like this:
I'm trying to extend H3EventContext like this:
However, the type H3EventContext seems not to exist anywhere (
import { H3EventHandler } from 'h3'
doesn't work).
Now, I found this issue that seems to be solved: https://github.com/unjs/h3/issues/122, but I don't understand how this works at all.
I've tried to add this to /server/graphql/context.ts:
But this does not seem to fix anything.GitHub
Issues · unjs/h3
⚡️ Minimal H(TTP) framework built for high performance and portability - Issues · unjs/h3
2 Replies
You should do it like this:
No need to import any h3 types for this if you are using nuxt
I place this in a
types.d.ts
at the root of my project@Gerbuuun Thanks.
It seems like I had some other problems with TypeScript to fix first.
And probably a restart of the server also fixed something.
Now I'm using
const context = event.context as Context
and it is working.
Your solution looks like the way to do it, but I coudn't get it to work in my project. I might try that again later.