将外部定义的组件与Vue和TypeScript类装饰器语法一起使用

时间:2019-06-06 18:37:02

标签: typescript vue.js vuejs2 vue-component vue-class-components

我正在尝试使用vue-form-wizard启用的TypeScript装饰器语法在Vue组件中使用vue-class-component

这是我的.vue文件:

<template>
    <form-wizard>
        <tab-content title="Personal details">
            My first tab content
        </tab-content>
        <tab-content title="Additional Info">
            My second tab content
        </tab-content>
        <tab-content title="Last step">
            Yuhuuu! This seems pretty damn simple
        </tab-content>
    </form-wizard>
</template>

<script lang="ts">
import Vue from 'vue';
import Component from "vue-class-component";
import { FormWizard, TabContent} from "vue-form-wizard";

@Component({
    components: {
        FormWizard, TabContent
    }
})
export default class AdvisorWizard extends Vue {
}
</script>

这是TypeScript生成的错误:

Argument of type '{ components: { FormWizard: typeof FormWizard; TabContent: typeof TabContent; }; }' is not assignable to parameter of type 'VueClass<Vue>'.
Object literal may only specify known properties, but 'components' does not exist in type 'VueClass<Vue>'. Did you mean to write 'component'?

我非常确定这是因为FormWizard没有扩展或以其他方式实现Vue。但是我无法弄清楚如何转换该组件或以其他方式强迫TypeScript相信FormWizard是Vue组件。

FormWizard的键入是否有可能是错误的?

export type ShapeType = 'circle' | 'square' | 'tab'
export type LayoutType = 'vertical' | 'horizontal'
export type StepSizeType = 'xs' | 'sm' | 'md' | 'lg'

export declare class Wizard {
  /** Wizard title */
  title: string
  /** Wizard subtitle */
  subtitle: string
  nextButtonText: string
  backButtonText: string
  finishButtonText: string
  /** Whether to hide footer buttons */
  hideButtons: boolean
  /** Whether to trigger beforeChange function when navigating back */
  validateOnBack: boolean
  /** Active step and button color */
  color: string
  /** Step color when the current step is not valid */
  errorColor: string
  /** Main step shape */
  shape: ShapeType
  /** Wizard layout */
  layout: LayoutType
  /** Additional css classes for steps */
  stepsClasses: string[]
  /** Step size */
  stepSize: StepSizeType
  /** Step transition from inactive to active */
  transition: string
  /** Tab index where the wizard should start */
  startIndex: number
}

如果是,我该怎么办?

1 个答案:

答案 0 :(得分:1)

vue-form-wizard中的类型定义为updated to address this problem,但从未发布。您可以使用以下命令手动安装包含更改的GitHub提交:

npm i -S git://github.com/BinarCode/vue-form-wizard#c686975