Using externally defined component with Vue and TypeScript class decorator syntax

Viewed 695

I'm trying to consume vue-form-wizard in a Vue component, using the TypeScript decorator syntax enabled by vue-class-component.

Here is my .vue file:

<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>

And here is the error TypeScript generates:

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'?

I'm pretty sure that this is because FormWizard doesn't extend or otherwise implement Vue. But I can't figure out how to cast the component or otherwise coerce TypeScript into believing that FormWizard is a Vue component.

Is it possible that the typings for FormWizard are just wrong?

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
}

If so, what can I do to fix it?

1 Answers

The type definitions in vue-form-wizard were updated to address this problem, but never released. You can manually install the GitHub commit that includes the changes, using this command:

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