typescript Number类型赋值错误?

新手上路,请多包涵

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就不会报错

阅读 2.2k
1 个回答

clipboard.png

对于number, boolean, string等基础类型,请直接使用这些类型命名即可,而大写开头的Number, Boolean, String只是构造函数而已

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题