#how can i use enum to create an tuple type?

9 messages · Page 1 of 1 (latest)

granite linden
#
enum SRSState {
  original = 0,
  right = 1,
  double = 2,
  left = 3,
}

type SRSBlockKickTable = [
  original:SRSStateKickTable,
  right:SRSStateKickTable,
  double:SRSStateKickTable,
  left:SRSStateKickTable,
]

I'm working on a modern tetris project, and I'm some how aggressive on my code quality. I don't want to write same stuff twice if possible, can i use enum above to define type below?

vagrant holly
#

Is it some other type, which you want as the value for each of the keys in the union?

#

If so, then what you need is a Record type
type SRSBlockKickTable = Record<keyof typeof SRSState, SRSStateKickTable>

granite linden
vagrant holly
#

If each value in SRSBlockKickTable has to be different according to the key, then you would probably need a mapped type

granite linden
#

okay

#

thanks