Returns an array of the object's keys with the correct type.

const destinations: Record<FormField, string> = { email: 'email', phoneNumber: 'phoneNumber' };
const keys = objectKeys(destinations); // type of Keys is FormField[] instead of string[] (which is the default type of Object.keys)
  • Type Parameters

    • T extends Record<keyof T, unknown>

    Parameters

    • object: T

    Returns (keyof T)[]