#Union of numbers between range

6 messages · Page 1 of 1 (latest)

runic fiber
#

Trying to create a type that would look something like

type Result = UnionOfRange<0, 3>
//   ^? Results = 0 | 1 | 2 | 3

Any geniuses around to help me out?

brave quartz
#
type UpTo<N extends number, A extends number[] = []> =
  A['length'] extends N ? A[number] : UpTo<N, [...A, A['length']]>
#

@runic fiber Might be possible to modify this to go from a different number than 0.

#

Honestly this is just a snippet that floats around this server, might be able to find a more advanced version if you search around.

runic fiber
#

Thanks, that works great. no idea how it works though

#

any clues?