Maa*_*ter 6 typescript vue.js visual-studio-code typescript-typings
我正在使用VSCode和TypeScript类进行Vue 2组件开发.请参阅:vuejs/vue-class-component.
在我当前的项目中,我使用插件,例如vue-i18n
标签的翻译等.这些插件扩展了Vue组件,它们具有自己的功能,例如this.$t(...)
通过密钥获得翻译,但是VSCode无法识别/不会关闭这些扩展(或者是mixins?)等
如何学习VSCode这些扩展函数是否存在且intellisense开始工作?我可以创建自己的*.d.ts文件吗?如果是这样,我怎么能把它们连接起来,以便VSCode可以找到它们用于intellisense?欢迎任何例子.或链接到一些示例Github repo这样做?
此问题现已解决并记录在 Vue TypeScript 文档中。它被称为“增强与插件一起使用的类型”。
以下片段来自此页面,以供快速参考:
// 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
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3133 次 |
最近记录: |