How to build a type from enum values in TypeScript?

后端 未结 3 1613
时光取名叫无心
时光取名叫无心 2021-01-17 10:53

Given the following:

enum FooKeys {
  FOO = \'foo\',
  BAR = \'bar\',
}

I\'d like to make an interface like this one, but instead of defini

3条回答
  •  死守一世寂寞
    2021-01-17 11:31

    yes?

    enum FooKeys {
      FOO = 'foo',
      BAR = 'bar',
    }
    
    interface Foo {
      foo: string
      bar: string
    }
    
    class Test implements Foo {
        public foo: string = FooKeys.FOO;
        public bar: string = FooKeys.BAR;
    }
    

提交回复
热议问题