nuxt-community/gtm-module

Type declaration file is missing

soerenmartius opened this issue · 3 comments

Can we add a types.d.ts to this module to have a better experience when using typescript?

Hi Folks, I am struggling with this issue as I have a nuxt and vue setup and I always get this error
Property '$gtm' does not exist on type 'CombinedVueInstance<Vue, unknown, unknown, unknown, Readonly<{ blok: any; }>>'.

Any idea on how to fix it locally until type file is included by default.

While there are no type definitions yet, you can use the following snippet to suppress build errors if strict type checking is on:

declare module "vue/types/vue" {
  interface Vue {
    readonly $gtm: any
  }
}

I just experienced this and below d.ts finally fixed.
Without import "vue/types/vue", some other plugins using import Vue from "vue" caused an error with Property "$xxx" does not exist on type.

// types/@nuxtjs/gtm.d.ts
import "vue/types/vue";

declare module "vue/types/vue" {
  interface Vue {
    readonly $gtm: any
  }
}