Function: typedObjectEntries()
typedObjectEntries<
T
>(obj
:T
): [keyofT
,T
[keyofT
]][]
Defined in: shared/utils/objectSafety.ts:218
Type-safe Object.entries that preserves key types for known object shapes.
Type Parametersโ
Tโ
T
extends Record
<PropertyKey
, unknown
>
Parametersโ
objโ
T
Object to get entries from
Returnsโ
[keyof T
, T
[keyof T
]][]
Array of [key, value] tuples with proper typing
Remarksโ
This function uses type assertion to preserve compile-time type information. The cast is safe for plain objects but should be used carefully with objects that may have prototype pollution, non-enumerable properties, or symbol keys. Object.entries() only returns enumerable string-keyed properties.
Exampleโ
const config = { timeout: 5000, retries: 3 } as const;
const entries = typedObjectEntries(config);
// Type: ["timeout" | "retries", number][]