2

I am doing a class with 3 methods to create new instances of that class, but when i try to that , the following error appears :

"Angular/Typescript - This expression is not constructable. Type 'MoveDataClass' has no construct signatures."

What i am doing wrong?

The class:

export class MoveDataClass {

    power;
    stab;
    efect;

    constructor(power,stab,efect) {
        this.power= power;
        this.stab =stab;
        this.efect= efect;

    }


}

What i do to create the new class :

 this.pokemonMovesCalculated[0] =  new this.moveData(type);

The error appears on the "this.moveData" in red

Fábio Heitor
  • 105
  • 2
  • 12

1 Answers1

0

To use a new instance of your class:

import { MoveDataClass} from './move.data'; // relative path
...
this.pokemonMovesCalculated[0] =  new MoveDataClass('one', 'two', 'three');

this is a short form of your class with default values:

export class MoveDataClass {

  constructor(
    public power = '',
    public stab = '',
    public efect = '') {
  }
}

This form can be used:

new MoveDataClass();
// or:
new MoveDataClass('one');
// or:
new MoveDataClass('one', 'two');
// or:
new MoveDataClass('one', 'two', 'three');
Marc
  • 1,836
  • 1
  • 10
  • 14