馃摎 Is your documentation request related to a problem? Please describe.
I was trying to extend the Context interface in a library by using the example in the Nuxt Typescript documentation:
declare module '@nuxt/types' {
interface Context {
$myInjectedFunction(message: string): void
}
}
So I can type the object returned by useContext, but I can't figure out a working combination, it seems to completely override the Context interface. So far I tried:
nuxt/index.d.ts in the library and add it in the tsconfig.json file -> overwrite the Context interface instead of extending it, doesn't even extend useContextglobal.d.ts file where I extend the Context myself -> same as aboveIs there a way to add this so it works both for Nuxt users and Vue users?
馃攳 Where should you find it?
I think this would be useful for anybody creating Composition API plugins that work with SSR
鈩癸笍 Additional context
For reference, this is the library I'm trying to add it to: https://github.com/posva/mande
@posva If you add nuxt/index.d.ts, just make sure to import the module you are extending, like so:
import '@nuxt/types'
declare module '@nuxt/types' {
interface Context {
$myInjectedFunction(message: string): void;
}
}
Hope this helps - and mande looks great!
Damn, I was just missing that import. Is this something you want to include in documentation in a new page or maybe you have a different idea?
That's a good idea. I've created a PR in the TS repo - your thoughts welcome.
Most helpful comment
That's a good idea. I've created a PR in the TS repo - your thoughts welcome.