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

Posted

技术标签:

【中文标题】模块扩充在 .vue 文件中不起作用【英文标题】:Module augmentation is not working in .vue file 【发布时间】:2020-02-06 09:56:19 【问题描述】:

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

import Vue from 'vue'

declare module 'vue/types/vue' 
  interface Vue 
    $test: string
  

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

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

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

但它只是在 .vue 文件中出现编译错误

谁能帮帮我?

【问题讨论】:

【参考方案1】:

尝试在你的tsconfig中添加types/*.d.ts到typeRoots

像这样:

"typeRoots": [
        "src/types"
    ],

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

【讨论】:

以上是关于模块扩充在 .vue 文件中不起作用的主要内容,如果未能解决你的问题,请参考以下文章