currentLeft是Number类型,但是赋Number值的时候却报错
class CardContainer {
currentLeft: Number
cards: Array<Card>
constructor () {
this.cards.sort(() => Math.random() - 0.5)
this.currentLeft = this.cards.length
}
dispatchCard (target: Player, num: Number) {
if (this.currentLeft < num) {
this.cards.sort(() => Math.random() - 0.5)
this.currentLeft = this.cards.length
}
let response = this.cards.splice(this.cards.length - this.currentLeft, num)
this.currentLeft = this.currentLeft - num
target.getCard(response)
}
}
如果把currentLeft类型改为any,num的类型改为any就不会报错
对于
number
,boolean
,string
等基础类型,请直接使用这些类型命名即可,而大写开头的Number
,Boolean
,String
只是构造函数而已