vue3 + typescript 全局属性设置类型报错

2023-12-13 15:48:27

报错

类型“{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<Readonly<{} & {} & {}> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>; ... 10 more ...; $watch(source: string | Function, cb: Function, options?: WatchOptions<...> | undefined): WatchStopHandle; } & ... 4 more ... & ComponentC...”上不存在属性“xxxxx”。时

在src文件下创建shims-vue.d.ts 文件

export {}
 
declare module 'vue' {
  interface ComponentCustomProperties {
    $filters: any
  }
}

注意:一定要添加export {} 不然会覆盖掉原来的

文章来源:https://blog.csdn.net/weixin_60196946/article/details/134906629
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。