Subscribe on changes!

关于扩展功能到this上的问题

avatar
Mar 11th 2021

Version

3.0.7

Reproduction link

https://codesandbox.io/s/vue-next-s3bf7?file=/src/components/HelloWorld.vue

Steps to reproduce

1、vue-cli4创建的vue ts项目,非class component 2、按照源代码中提供的例子将声明添加至shims-vue.d.ts文件当中 declare module '*.vue' { import type, { DefineComponent } from 'vue' const component: DefineComponent<{}, {}, any> export default component } declare module '@vue/runtime-core' { interface ComponentCustomProperties { $http:any, } } 3、重新项目会发现引入的.vue组件找不到 4、将声明移入到main.ts中项目正常运行

What is expected?

是否可以统一将声明文件放置shims-vue.d.ts中

What is actually happening?

不成功

avatar
Mar 11th 2021
//main.ts
declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $http:any,
  }
}

Do not put it into .d.ts

avatar
Mar 11th 2021

Remember to use the forum or the Discord chat to ask questions!

avatar
Mar 11th 2021

@LinusBorg why? 那假如后期还需要引入类似这些声明文件,难道都需要引入到main.ts中吗

avatar
Mar 11th 2021

@posva @LinusBorg