0 of 6 problems solved0%
1 of 6

List Object Keys Safely

keyof T creates a union of an object type’s property names. Array<keyof T> represents a list of those names. When you call Object.keys, you get string[], so you often cast the result to Array<keyof T> to keep types precise.

function keysOf<T extends object>(o: T): Array<keyof T> {
  return Object.keys(o) as Array<keyof T>;
}

Prefer returning a new array. Assume normal insertion order from JavaScript objects when testing with literals.

Your Task

Create a function that returns the typed keys of an object.

  • Implement function listKeys<T extends object>(o: T): Array<keyof T>.
  • Return a new array with the object’s own enumerable keys.
  • Do not mutate the input object.
  • Keep the return type as Array<keyof T>.