typescript - 如何在模块扩充中引用 ComponentOptions 的其他泛型参数?
问题描述
这是我想在我的.d.ts
文件中执行的操作:
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
beforeInstance?: (options: ComponentOptions<V>) => void | Promise<(vm: CombinedVueInstance<V, Data, Methods, Computed, Props>) => any | undefined>;
}
}
它没有工作,因为它不知道Data
,Methods
和。我已经尝试将这些变量放入如下:Computed
Props
ComponentOptions
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue, Data=DefaultData<V>, Methods=DefaultMethods<V>, Computed=DefaultComputed, PropsDef=PropsDefinition<DefaultProps>, Props=DefaultProps> {
beforeInstance?: (options: ComponentOptions<V>) => void | Promise<(vm: CombinedVueInstance<V, Data, Methods, Computed, Props>) => any | undefined>;
}
}
它会破坏我的组件定义中的类型推断:
export default Vue.extend({
data: function () {
return {
value: 'abc'
};
},
mounted: function () {
console.log(this.value); // This does not work.
}
});
解决方案
推荐阅读
- ionic3 - Ionic v3:如何将离子网格表复制到 excel
- r - 如何在数据框的变量标签中搜索字符串,并在 R 中返回包含所有这些变量的向量
- javascript - 递归?我了解基础知识,但无法理解此代码的流程
- ruby-on-rails - 在 app/controllers 文件夹外自动加载 rails 控制器
- android - 如何摆脱我的颤动代码周围的这些奇怪的边界线?(在 android studio 中颤动)
- python - 在 Python 中跨日历季度的财政季度拆分收入
- powershell - 在 foreach 循环的第二次迭代中引用函数中的第二个参数
- git - 是否可以强制“git diff”为不在存储库中的文件显示“相似度索引”
- c - C MPI 并行编程 - 分段错误 11 错误
- python - Pandas 数据框中的 Ping 主机