ANGLING/TypeScrip-此表达式不可构造。类型MoveDataClass';没有构造签名 [英] Angular/Typescript - This expression is not constructable. Type 'MoveDataClass' has no construct signatures
本文介绍了ANGLING/TypeScrip-此表达式不可构造。类型MoveDataClass';没有构造签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个具有3个方法的类,以创建该类的新实例,但当我尝试这样做时,出现以下错误:
"角度/类型脚本-此表达式不可构造。类型‘MoveDataClass’没有构造签名。"
我做错了什么?
类:
export class MoveDataClass {
power;
stab;
efect;
constructor(power,stab,efect) {
this.power= power;
this.stab =stab;
this.efect= efect;
}
}
创建新类的操作:
this.pokemonMovesCalculated[0] = new this.moveData(type);
错误以红色显示在"this.moveData"上
推荐答案
使用您的类的新实例:
import { MoveDataClass} from './move.data'; // relative path
...
this.pokemonMovesCalculated[0] = new MoveDataClass('one', 'two', 'three');
这是您的类的缩写形式,具有默认值:
export class MoveDataClass {
constructor(
public power = '',
public stab = '',
public efect = '') {
}
}
可以使用此表单:
new MoveDataClass();
// or:
new MoveDataClass('one');
// or:
new MoveDataClass('one', 'two');
// or:
new MoveDataClass('one', 'two', 'three');
这篇关于ANGLING/TypeScrip-此表达式不可构造。类型MoveDataClass';没有构造签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文