模块扩充在 .vue 文件中不起作用

Bab*_*age 6 typescript vue.js vue-component typescript-typings vuejs2

有一个模块扩充(types/test.d.ts):

import Vue from 'vue'

declare module 'vue/types/vue' {
  interface Vue {
    $test: string
  }
}
Run Code Online (Sandbox Code Playgroud)

并将其包含为(tsconfig.json):

// ...
"include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx",
    "types/*.d.ts"
  ],
// ...

Run Code Online (Sandbox Code Playgroud)

然后,它在任何.ts文件中都能正常工作:

在此处输入图片说明 在此处输入图片说明

但它只是在.vue文件中 得到一个编译错误在此处输入图片说明

有人可以帮助我吗?

Pao*_*rro 1

尝试将 types/*.d.ts 添加到 yout tsconfig 中的 typeRoots

像这样:

"typeRoots": [
        "src/types"
    ],
Run Code Online (Sandbox Code Playgroud)

(通常我使用@types来存储我的.d.ts文件)