Skip to content

Instantly share code, notes, and snippets.

@gabiseabra
Last active January 8, 2022 21:05
Show Gist options
  • Select an option

  • Save gabiseabra/151799d2942be4063111450a040e6cd7 to your computer and use it in GitHub Desktop.

Select an option

Save gabiseabra/151799d2942be4063111450a040e6cd7 to your computer and use it in GitHub Desktop.
type Ix = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
type KVMap<T extends { k: string, v: any }> = {
[k in T['k']]: Extract<T, { k: k }>['v']
}
type ZipKVMap<K extends string[], V extends any[]> = {
[ix in Ix]
: K[ix] extends string
? V[ix] extends infer T
? { k: K[ix], v: T }
: never
: never
}[Ix]
type ZipMap<K extends string[], V extends any[]> = KVMap<ZipKVMap<K, V>>
type T = ZipMap<["a", "b"], [string, number]> // T = { a: string, b: number }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment