#Using a "ws"plugin inside a store, unkown type?!?
2 messages · Page 1 of 1 (latest)
When you provide a property like $ws from a Nuxt plugin, it is available at runtime via useNuxtApp(), but TypeScript may not recognize its type automatically. This often results in TypeScript errors such as "Object is of type 'unknown'" when accessing $ws in your store or components.
To resolve this, you need to augment the NuxtApp type so TypeScript knows about your injected property. Here’s how you can do it:
- Create or update a type declaration file (e.g., index.d.ts) in your project root:
declare module '#app' {
interface NuxtApp {
$ws: YourWsType // Replace with the actual type of your ws instance
}
}
declare module 'vue' {
interface ComponentCustomProperties {
$ws: YourWsType
}
}
export {}
- After this, TypeScript will recognize $ws when you use useNuxtApp() or in your components.
This approach is documented in the Nuxt docs for plugin typing. Note that if you are using JetBrains IDEs (like WebStorm or PhpStorm), there is a known bug where these types may not be recognized even if everything is set up correctly. In that case, try using VSCode to confirm your setup works as expected Custom plugin in nuxt 3 has unknown type and Using Composables & Typing Plugins.