我正在使用 VSCode 和 TypeScript 类进行 Vue 2 组件开发。请参阅:vuejs/vue-class-component .
在我当前的项目中,我使用像 vue-i18n
这样的插件来翻译标签等。这些插件使用它们自己的功能扩展 Vue 组件,如 this.$t(...)
通过键获得翻译,但 VSCode 不识别/不关闭这些扩展(或者它们是 mixins?)等。
如何让 VSCode 知道这些扩展函数存在并且 intellisense 开始工作?我可以创建自己的 *.d.ts 文件吗?如果是这样,我如何将它们连接起来以便 VSCode 可以找到它们以进行智能感知?欢迎任何例子。或者链接到完成此操作的一些示例 Github 存储库?
最佳答案
此问题现已解决并记录在 Vue TypeScript 文档中。它叫做"Augmenting Types for Use with Plugins" .
以下片段来自此页面以供快速引用:
// For example, to declare an instance property $myProperty with type string:
// 1. Make sure to import 'vue' before declaring augmented types
import Vue from 'vue'
// 2. Specify a file with the types you want to augment
// Vue has the constructor type in types/vue.d.ts
declare module 'vue/types/vue' {
// 3. Declare augmentation for Vue
interface Vue {
$myProperty: string
}
}
关于typescript - VSCode 和 Vue 2 插件 TypeScript 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42028790/