Búsqueda de sitios web

vue.js - Usando un componente definido externamente con Vue y la sintaxis de decorador de clase de TypeScript


Estoy tratando de usar vue-form-wizard en un componente de Vue, utilizando la sintaxis de decoradores de TypeScript habilitada por vue-class-component.

Aquí está mi archivo .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>

Y aquí está el error que genera 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'?

Estoy bastante seguro de que esto se debe a que FormWizard no extiende ni implementa de alguna otra manera a Vue. Pero no puedo averiguar cómo convertir el componente o forzar de alguna manera a TypeScript a creer que FormWizard es un componente de Vue.

¿Es posible que las definiciones de tipos para FormWizard estén simplemente equivocadas?

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
}

Si es así, ¿qué puedo hacer para solucionarlo?

Respuesta #1

Las definiciones de tipo en vue-form-wizard se actualizaron para abordar este problema, pero nunca se lanzaron. Puedes instalar manualmente el commit de GitHub que incluye los cambios, usando este comando:

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

Artículos relacionados