简体   繁体   English

vue类组件mixins在WebStorm中引发错误?

[英]vue-class-component mixins provoke an error in WebStorm?

I'm working on a project using vue-js and TypeScript. 我正在使用vue-js和TypeScript进行项目。 So I give vue-class-component a try. 因此,我尝试了vue-class-component

I'm trying to code a mixin, it works well in VSC and VS but it seems that WebStorm is not really happy with my code. 我正在尝试编写一个混合代码,它在VSC和VS中都能很好地工作,但是WebStorm似乎对我的代码并不满意。

Here is the mixin : 这是mixin:

import Vue from 'vue'
import {StoreOptions} from 'vuex'
import Component from "vue-class-component";

@Component
export default class Container extends Vue {
  registerStoreModule(key: string, module: StoreOptions<any>): void {
    if (!this.$store.state[key]) {
      this.$store.registerModule(key, module);
    }
  }
}

And here is the component using this mixin : 这是使用此mixin的组件:

  @Component({
    components: { UserCard },
    computed: mapGetters({ user: `${STORE_KEY}/user` })
  })
  export default class UserContainer extends mixins(Container) {
    user: UserState;

    created() {
      this.registerStoreModule(STORE_KEY, store)
    }

    mounted() {
      this.$store.dispatch(`${STORE_KEY}/getUser`);
    }
  }

According to vue-class-component , this should work. 根据vue-class-component ,这应该工作。 The thing is that WebStorm is failing at checking TypeScript types. 事实是,WebStorm无法检查TypeScript类型。

臭虫?

There are 2 errors : 有2个错误:

  • Argument types do not match parameters 参数类型与参数不匹配
  • Base constructors must all have the same return type 基本构造函数必须都具有相同的返回类型

The code compiles well and other IDEs don't catch those errors. 代码可以很好地编译,而其他IDE不会捕获这些错误。 I've tried with different versions of TS, currently I'm using 2.8.3. 我尝试使用不同版本的TS,目前使用的是2.8.3。 Visual Studio Code uses the same version as WebStorm. Visual Studio Code使用与WebStorm相同的版本。

EDIT: Here is my tsconfig.json, it can be useful :) 编辑:这是我的tsconfig.json,它可能有用:)

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "node",
      "mocha",
      "chai"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    }
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.vue",
    "tests/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

已知问题,请按照WEB-31543进行更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 vue-class-component &amp; Mixins - vue-class-component & Mixins vue-class-component如何同时使用基类和mixins? - How can both a base class and mixins be used with vue-class-component? Vuelidate 与 Vue 3 + vue-class-component + TypeScript - Vuelidate with Vue 3 + vue-class-component + TypeScript Vue JS - vue-class-component 绑定输入 - Vue JS - vue-class-component binding input VueJS 组件:具有 vue-class-component 的单独文件的代码覆盖率 - VueJS Component: Code coverage for separate file with vue-class-component vue-class-component:如何创建和初始化反射数据 - vue-class-component : how to create and initialize reflective data Vue 2.5 vue-class-component使用Vue命名空间,但是它是Type - Vue 2.5 vue-class-component uses Vue namespace but it's a Type Vue&TypeScript:vue-property-decorator / vue-class-component的&#39;el&#39;属性? - Vue&TypeScript: 'el' property for vue-property-decorator/vue-class-component? vue-class-component + typescript:如何在导入的 function 中使用组件的 class 作为“this”类型? - vue-class-component + typescript: how to use a component's class as a type of "this" in imported function? 使用vue-class-component的Vue Router:next函数不接受回调选项 - Vue Router with vue-class-component: next function does not accept callback option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM