JS Built-ins
TypeScriptbeginner

Utility Types β€” keyValuePairs

πŸ“– Usage Example
keyValuePairs({ a: 1, b: 2 })   // β†’ [['a', 1], ['b', 2]]

keyValuePairs converts an object into an array of typed [key, value] tuples using Object.entries.

Utility Types: Object Entries to Typed Array

Challenge: Implement keyValuePairs<T extends object>(obj: T): [keyof T, T[keyof T]][] returning all entries as typed tuples.

keyValuePairs({ a: 1, b: 'x' })  // β†’ [['a', 1], ['b', 'x']]
πŸ’‘ Hints (1)
  • β€’ Object.entries returns [key, value] pairs β€” just cast for TypeScript.