Enum as Parameter in TypeScript

后端 未结 9 1780
故里飘歌
故里飘歌 2020-12-01 13:18

Isn\'t it possible to set the type of a parameter to an Enum? Like this:

private getRandomElementOfEnum(e : enum):string{
    var length:number = Object.         


        
9条回答
  •  日久生厌
    2020-12-01 14:23

    Another possible option not mentioned above is using the actual values. This is however possible only when you know all the options. This, in my opinion is definitely better than any.

        doSomething(a: string, b: 'this'|'can'|'work'): void {
         //do something
        }
    

提交回复
热议问题