ts2339错误:如何在Vue.js项目中使用Typescript Mixin? [英] ts2339 error: how to use typescript mixin in vuejs project?

查看:849
本文介绍了ts2339错误:如何在Vue.js项目中使用Typescript Mixin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的vuejs转换为打字稿库,但是现在我在打字稿中使用mixin遇到了问题. 我使用了两种类型的mixin,但没有一种适用于我,并且显示错误ts2339,我无法在 https://vuejs.org/v2/guide/typescript.html#Basic-Usage : 第一个:

i recently converted my vuejs to typescript base, but now i have problem with using mixin in typescript. i used two types of mixin, but none worked for me and it shows error ts2339, and i couldnt found the solution on https://vuejs.org/v2/guide/typescript.html#Basic-Usage: first one:

//mixin.ts
import {ViewState} from "@/types";
import {mocked_view_state} from "@/api/mock/profile.device.group.mock";

export const ProfileDeviceGroup = {
  methods: {
    resetViewState(): ViewState {
      return mocked_view_state;
    }
  }
};

第二个:

//mixin.ts
import Vue from "vue";
import {ViewState} from "@/types";
import {mocked_view_state} from "@/api/mock/profile.device.group.mock";

const ProfileDeviceGroup = Vue.extend({
  methods: {
    resetViewState(): ViewState {
      return mocked_view_state;
    },

  }
});
export default ProfileDeviceGroup;

那么,有什么办法可以解决这个问题?

so, is there any way to fix this problem?

..............

..............

更新:

..............

..............

使用vue-typed-mixins后,问题已解决,但另一个问题暴露出来,如下图所示:

after using vue-typed-mixins, the problem has been solved, but another problem exposes as you can see in below picture:

推荐答案

基于此问题 https://github.com/ktsn/vue-typed-mixins/issues/4 我在vue-typed-mixins的github中创建的,这是一个未解决的问题,作者认为webstorm和Vuetr插件应该修复,并且与vue-typed-mixins无关. 但是我认为问题仍然与vue-typed-mixins插件有关,但是我希望这个问题能尽快解决,并应该感谢vue-typed-mixins团队,webstorm团队和Vuetr的作者.

based on this issue https://github.com/ktsn/vue-typed-mixins/issues/4 which i created in vue-typed-mixins's github, it is a not-fixed issue which the author believes webstorm and Vuetr plugin should fix, and its not related to vue-typed-mixins. however i think the problem still is related to vue-typed-mixins plugin, but i hope the problem will be fixed soon and should thank the author of vue-typed-mixins team, and webstorm team and Vuetr.

对于那些像我一样想要继续使用vue + typescript的人来说,似乎有一种更好的方法来解决这些问题,这是 vue2-composition-api ,有些团队拥有一直在使用,并告诉我打字稿还可以,并且没有问题,因为不再需要使用mixin. vuejs2.x合成api是否与打字稿完全兼容?

for those who (like myself) want to keep going with vue+typescript, there seems to be a better way to pass these problems, which is vue2-composition-api, which some teams has been using and told me it was ok with typescript and has no problem since there is no need to use mixin anymore. is vuejs2.x composition api fully compatibile with typescript?

我希望它能起作用...

i hope it work...

这篇关于ts2339错误:如何在Vue.js项目中使用Typescript Mixin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆