language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

`ComponentCustomProperties` in `vue` module not recognized

Open lzurbriggen opened this issue 1 year ago • 3 comments

the vue documentation recommends declaring custom component properties in the vue module, like this:

declare module 'vue' {
  interface ComponentCustomProperties {
    $gettext: MyType
  }
}

however the language server reports usages in templates as errors (Property '$gettext' does not exist on type '{ $: ComponentInternalInstance; ...).

declaring them in @vue/runtime-core still works, and is the way e.g. vue-router does it:

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
     $gettext: MyType
  }
}

i know the vue language tools readme mentions @vue/runtime-core regarding global components, but there's not really any other documentation regarding this, so i'd rather follow the vue docs.

i think this broke with the latest release.

versions:

  • vue language features/vue-tsc: 1.8.4
  • vue: 3.3.4
  • typescript: 5.1.6

lzurbriggen avatar Jul 06 '23 09:07 lzurbriggen

#3107 Weird...

so1ve avatar Jul 06 '23 14:07 so1ve

I'm having the same problem, it's weird, is the documentation wrong or is this a pending bug, https://cn.vuejs.org/guide/typescript/options-api.html#augmenting-global-properties

watchingfun avatar Apr 28 '24 05:04 watchingfun

I'm having the same problem, it's weird, is the documentation wrong or is this a pending bug, https://cn.vuejs.org/guide/typescript/options-api.html#augmenting-global-properties

It is normal to use declare module 'vue' in vscode, and it is normal to change it to declare module '@vue/runtime-core' in webstrom.

watchingfun avatar Apr 28 '24 05:04 watchingfun

Close since this problem has nothing to do with language tools, please ask the TS question in the Vue Discord server.

johnsoncodehk avatar May 13 '24 20:05 johnsoncodehk

Sorry, I haven't looked into this in detail yet, but could it have something to do with vue-tsc using @vue/runtime-core instead of vue?

saifahn avatar May 31 '24 06:05 saifahn

I also get the same error when running type checking until you replace vue with @vue/runtime-core in the declaration

https://github.com/GurovDmitriy/be-boilerplate-stack in vue-playground template find declare $mq: PluginBreakpoints

GurovDmitriy avatar Jun 14 '24 09:06 GurovDmitriy

  1. you have to install it: pnpm add -D @vue/runtime-core

  2. In the .d.ts file import the interface: import { ComponentCustomProperties } from '@vue/runtime-core'

  3. Add the declaration: declare module "@vue/runtime-core" { interface ComponentCustomProperties { route: typeof ziggyRoute; } }

  4. If it necessary and you use vscode, reload the TS Server and reload window with Ctrl+Shift+P

cristianTalero avatar Jul 06 '24 20:07 cristianTalero

You don't have to install it, nor import { ComponentCustomProperties } from '@vue/runtime-core'

so1ve avatar Jul 08 '24 00:07 so1ve

Yeah, but in my case only the instalation, the import was necesary, because when I remove it, I get the linter error again, I'm not sure why

cristianTalero avatar Jul 08 '24 03:07 cristianTalero