收起左侧

[前端] Vue3+TS配置全局属性后ESLint出现类型不存在问题

0
回复
[复制链接]

5

主题

-5

回帖

60

积分

发表于 2022-12-23 15:32:26 | 显示全部楼层 |阅读模式
​编辑​​问题: 类型“{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<Readonly<ExtractPropTypes<{}>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>; ... 10 more ...; $watch(source: string | Function, cb: Function, options?: WatchOptions<...> | undefined): WatchStopHandle; } & ... 5 more ... & Sh...”上不存在属性“$filters”。
新增加的全局属性,ESLint上识别不了,我之前的解决方案是直接在 shims-vue.d.ts上声明变量的,但是发现并没有能解决这个报错(可能是版本原因,之前确实可以这样操作)。
declare let $store: anydeclare let $filters: any
后来找了一下解答。有以下解决方案:
解决:
在shims-vue.d.ts中添加或者新建一个`.ts`或".d.ts"文件。
// 代码一//必需export 否则会导致路由找不到文件及main.ts产生错误export {} declare module 'vue' {  interface ComponentCustomProperties {    $filters: any  }}
但是我的版本里面创建项目之后就自动生成了以下代码,如果直接在declare module '*.vue'里面直接添加并没有什么效果,另外直接在我的原文件下添加 declaer module 'vue' { interface xxx }还会产生新问题: ERROR in src/views/main/system/department/department.vue:8:10(vue-router查找文件识别)
// 代码二/* eslint-disable */declare module '*.vue' {  import type { DefineComponent } from 'vue'  const component: DefineComponent<{}, {}, any>  export default component}
最终我是创建了一个新的.d.ts文件添加代码一.


参与人数 1金币 +60 收起 理由
itjc8 + 60 赞一个!

查看全部评分总评分 : 金币 +60

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则