Function: typedObjectKeys()
typedObjectKeys<
T
>(obj
:T
): keyofT
[]
Defined in: shared/utils/objectSafety.ts:248
Type-safe Object.keys that preserves key types for known object shapes.
Type Parametersโ
Tโ
T
extends Record
<PropertyKey
, unknown
>
Parametersโ
objโ
T
Object to get keys from
Returnsโ
keyof T
[]
Array of keys with proper typing
Remarksโ
This function uses type assertion to preserve compile-time type information. Note that Object.keys() only returns enumerable string-keyed properties, so symbol keys are not included in the result. The cast assumes all keys are of type keyof T, which is safe for plain objects but may not include all possible keys for objects with symbol keys or inherited properties.
Exampleโ
const config = { timeout: 5000, retries: 3 } as const;
const keys = typedObjectKeys(config);
// Type: ("timeout" | "retries")[]