200.Land

to-tuple-type.ts

This TypeScript code defines a type alias ToTupleType that takes two type parameters: B, an object type, and F, a tuple of key strings representing keys of B. It maps over the tuple F, creating a new tuple type where each element is the type of the corresponding property in B. It essentially helps in transforming an object into a tuple type with a specific set of properties.

type ToTupleType<B, F extends (keyof B)[]> = {
  [K in keyof F]: F[K] extends F[number] ? B[F[K]] : never;
};