Home > Back-end >  Type Function is not a function constructor type though Typescript version is above 4.7
Type Function is not a function constructor type though Typescript version is above 4.7

Time:09-23

I changed typescript config to support decorators and then type from https://blog.logrocket.com/a-practical-guide-to-typescript-decorators/ :

const addFuelToRocket = (target: Function) => {
  return class extends target {
    fuel = 100
  }
}

In Vscode I get this Type Function error whereas according to Type ... is not a constructor function type it shouldn't with version above 2.2, my typescript version in vscode at bottom is 4.7.3

CodePudding user response:

The function needs a construct signature for you to extend it:

const addFuelToRocket = (target: { new(...args: any[]): any }) => {
  return class extends target {
    fuel = 100
  }
};

Playground

  • Related