TS2339:vue类组件中的类型“ MyComponent”上不存在属性“ xxx”

时间:2020-01-28 10:31:46

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

有人知道如何正确地告诉TypeScript如何了解我在第一张照片上授权的Prop的{​​{1}}吗?

  1. 此人宣布typePropimage 1
engine
  1. 在这里,我从第一张图片扩展了组件 image 2
<script lang="ts">
 import Vue from 'vue';
 import { Component, Prop, Watch, Mixins } from 'vue-property-decorator';
 import pDebounce from 'p-debounce';

 // Define the props by using Vue's canonical way.
 export const FetcherProps = Vue.extend({
   props: {
     engine: Function
   }
 })
 // Use defined props by extending GreetingProps
 @Component
 class Fetcher extends FetcherProps {
   response: Array<any> | Promise<any> = [];
   fetch2: Function;

   // @Prop() engine!: Function;
   // @Prop({ default: null }) debounce!: null | number;
   // @Prop({ default: () => {} }) request!: Dictionary<any>;
   // @Prop({ default: true }) promisify!: boolean;

   get requestObject() {
     return { params: this.request };
   }
  1. (与上图相同的组件)问题是TypeScript无法正确推断引擎类型image 3
@Component({})
  class EmSearchEngine extends Fetcher {

在此之前,我尝试在仓库中使用示例文件夹中的一个示例:https://github.com/vuejs/vue-class-component/blob/master/example/src/App.vue,但这对我没有帮助。

我的代码有问题吗?还是我必须在 render(h: CreateElement) { return h(Fetcher, { props: { debounce: 300, promisify: false, engine: this.engine <-- "TS2339: Property 'engine' does not exist on type 'EmSearchEngine'., request: { ...this.initialQuery, ...this.query, cancelToken: new CancelToken((cancel) => { abortSearch = cancel; }) } 组件上明确声明engine类的属性?

在此先感谢您的帮助。原始github的问题:https://github.com/vuejs/vue-class-component/issues/391

0 个答案:

没有答案