添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

类型“{ $: 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: any
declare 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文件添加代码一。

附上官方文档:TypeScript 与选项式 API | Vue.js

参考来源:vue3 + typescript 全局属性设置类型报错_何为枕边人的博客-CSDN博客

1.关闭类型警告: 找到.eslintrc.js文件,找到rules,配置如下代码 "@typescript-eslint/no-explicit-any": ["off"] 没有自己创建一个文件,把这个文件名粘贴过去 2.重新运行项目 data: {};} & ... 4 more ... & ComponentC...”上不存在属性“xxxxx”。在src文件下创建shims-vue.d.ts 文件。 类型Vue3Instance & ... 4 more ... & Readonly”上不存在属性“handleOpen”。在网上寻找诸多办法无果,比如加any,在一个json文件中加语句,重启等等。 部分报错信息: error TS2339: Property ‘$urlLink’ does not exist on type '{ $: ComponentInternalInstance;$data: {};: unknown;上述操作完之后就不会报错可以打包了! Property '$URL' does not exist on type '{ $: ComponentInternalInstance; $data: {}; $props: Partial & Omit 在项目中使用$store出现以下:类型“{ $: ComponentInternalInstance;$data: {};: unknown;class?: unknown;key?ref?ref_for?$watch