首页 > 解决方案 > TS2339:vue-class-component 中的“MyComponent”类型上不存在属性“xxx”

问题描述

有谁知道如何正确地告诉 TypeScript 如何了解我在第一张照片上Proptype权利?

  1. 这家伙宣称Propengine图 1
<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. 在这里,我从第一个图片 图像 2扩展组件
@Component({})
  class EmSearchEngine extends Fetcher {
  1. (与上图相同的组件)问题是 TypeScript 无法正确推断引擎类型图 3

    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;
            })
          }

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

我的代码有问题还是我必须engine在组件上明确声明类的属性EmSearchEngine

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

标签: typescriptvue.jsvue-class-components

解决方案


推荐阅读