Typescript extending Enum

前端 未结 1 1513
轮回少年
轮回少年 2021-01-28 18:55

The case is you have a list of constants or Enum how you can do it ?

Here is the pseudo example code:

enum MyList
{
    A,
    B
}

enum MyList2
{
    C
         


        
相关标签:
1条回答
  • 2021-01-28 19:38

    This is a longstanding issue with numeric enums. For whatever reason (some backwards compatibility they can't break), a number is seen as assignable to a numeric enum, so you can do this with no error:

    enum E {
      V = 100
    }
    const num = 100;
    const e: E = num; // no error                                                                     
    0 讨论(0)
提交回复
热议问题