Inheritance method call triggers Typescript compiler error

后端 未结 2 1725
陌清茗
陌清茗 2020-12-18 00:30

I am having an issue with webstorm typescript compiler. I have the following classes

export class rootData{
  id:string
  //...

  constructor(){
    //...
         


        
2条回答
  •  鱼传尺愫
    2020-12-18 00:53

    Because super calls are redirected to the prototype you cannot use a property and need to use a method i.e. can't use = ()=>.

    Fixed code:

    export class rootData{
      id:string
      //...
    
      constructor(){
        //...
      }
    
      insert():Promise{
        //...
      }
    }
    
    class child extends rootData {
      //...   
    
      constructor(){
         super();
      }
    
      insert():Promise {
            return super.insert();
        }
    }
    

提交回复
热议问题