Vuetify 2 类型错误:找不到名称“DefaultProps”

Seb*_*sin 6 typescript vue.js ts-loader vuetify.js vue-cli

由于我更新了我的项目以使用 Vuetify ( https://vuetifyjs.com )的新 2.x 版本,我在编译过程中遇到了一些类型错误,我不知道如何摆脱它们。正确地只是我的 tsconfig 以某种方式关闭。

我检查了文档并确保在我的 tsconfig.json 的类型部分中包含 vuetify,如下所示:

{
  "compilerOptions": {
    ...

    "types": [
      "webpack-env",
      "jest",
      "vuetify",
      "axios"
      ],

     ...
  }
}
Run Code Online (Sandbox Code Playgroud)

我在这里不做任何花哨的事情:

import Vue from 'vue';
import App from './App.vue';
import vuetify from './plugins/vuetify';
import router from './router';
import store from './store';

Vue.config.productionTip = false;

new Vue({
  vuetify,
  router,
  store,
  render: (h) => h(App),
}).$mount('#app');
Run Code Online (Sandbox Code Playgroud)

然后我运行开发服务器: yarn serve

ERROR in /Users/sebe/workspace/app/frontend/arena/src/main.ts
12:3 Argument of type '{ vuetify: Vuetify; router: VueRouter; store: Store<any>; render: (h: CreateEle
ment) => VNode; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, Def
aultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'.
  Object literal may only specify known properties, and 'vuetify' does not exist in type 'ComponentOpt
ions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>
, Record<string, any>>'.
     8 | 
     9 | new Vue({
  > 10 |   vuetify,
       |   ^
    11 |   router,
    12 |   store,
    13 |   render: (h) => h(App),

ERROR in /Users/sebe/workspace/app/node_modules/vuetify/types/index.d.ts
59:10 Cannot find name 'DefaultData'.
    57 |   export interface ComponentOptions<
    58 |     V extends Vue,
  > 59 |     Data=DefaultData<V>,
       |          ^
    60 |     Methods=DefaultMethods<V>,
    61 |     Computed=DefaultComputed,
    62 |     PropsDef=PropsDefinition<DefaultProps>,
Run Code Online (Sandbox Code Playgroud)

第二个错误对 DefaultProps、PropsDefinition、DefaultComputed、DefaultMethods 重复。

任何人的帮助都会很棒:)

更新:我刚刚注意到我在使用默认的 vuetify 打字稿模板时遇到了同样的错误:

vue create newapp
vue add vuetify
yarn serve
Run Code Online (Sandbox Code Playgroud)

./plugins/vuetify.ts看起来像这样:

import Vue from 'vue';
import Vuetify from 'vuetify/lib';
import colors from 'vuetify/lib/util/colors';
import { VuetifyPreset } from 'vuetify/types/presets';

Vue.use(Vuetify);

const opts: Partial<VuetifyPreset> = {
  theme: {
    dark: true,
    themes: {
      light: {
        primary: colors.green.base,
      },
      dark: {
        primary: colors.green.darken2,
      },
    },
  },
  icons: {
    iconfont: 'mdi',
  },
};

export default new Vuetify(opts);
Run Code Online (Sandbox Code Playgroud)

Wil*_*tié 2

我遇到了同样的问题,结果发现这是因为我的路径中有一个符号链接:

/c/linkToDev/vueApp- 总是失败

/d/devFolder/vueApp- 一直工作