简体   繁体   中英

typescript shot form notation of used Enum in interface

Is there any way to shorten this piece of code? Basically I do not want to write Aa, Ab, etc. Some how I just want to write A and type script will understand it needs to be one of the enum values.

Thanks

enum A {
  a: 'one',
  b: 'two',
  c: 'three'
}

interface check {
  type: A.a|A.b|A.c
}

enums should be used in below way

enum A{
  a:'one',
  b:'two',
  c:'three'
}
interface check{
 type:A
}

in this way, check.type can have values 'one', 'two', 'three'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM