objectKeys
Works the same as Object.keys() but preserves the key type.
Note that symbol properties are excluded since they are not enumerable.
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);