簡體   English   中英

打字稿:如何重載受保護的類常量

[英]Typescript : How to overload a protected class constant

使用打字稿,在定義具有繼承的類時,是否可以重載受保護的常量?

例子:

class A {
   static defaultProps = {
      message: ''
   }
}

class B extends A {
   static defaultProps = {
      // get defaultProps from A,
      title: ''
   }
}

我不知道使用 React 是否重要。

您應該只從A類擴展defaultProps道具(注意: defaultProps是 ˙static` 以便您可以在類上而不是在實例上訪問它)

以下應該工作:

class A {
   static defaultProps = {
      message: ''
   }
}

class B extends A {
   static defaultProps = {
      ...A.defaultProps,
      title: ''
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM