Skip to main content

objectKeys

Works the same as Object.keys() but preserves the key type. Note that symbol properties are excluded since they are not enumerable.


Code

🔗 View source code


Interface

typescript
type ObjectKeys<T extends Record<PropertyKey, any>> = Exclude<
keyof T,
symbol
>;

function objectKeys<T extends Record<PropertyKey, any>>(
obj: T
): ObjectKeys<T>[];

Usage

typescript
import { objectKeys } from '@modern-kit/utils';

const symbol = Symbol('d');
const obj = {
a: 1,
b: 2,
c: 3,
[symbol]: 4,
} as const;

/**
* type: ("a" | "b" | "c")[]
* value: ["a", "b", "c"]
*/
const keys = objectKeys(obj);

Note