Typescript: constants in an interface

后端 未结 5 1301
一生所求
一生所求 2020-12-17 14:31

How do I place a constant in an Interface in typescript. Like in java it is:

interface OlympicMedal {
  static final String GOLD = \"Gold\";
  static final S         


        
5条回答
  •  -上瘾入骨i
    2020-12-17 15:05

    This seems to work:

    class Foo {
      static readonly FOO="bar"
    }
    
    export function foo(): string {
      return Foo.FOO
    }
    

    You can have private constants as well like this. It seems interfaces can't have static members though.

提交回复
热议问题