Function: safeObjectPick()
safeObjectPick<
T,K>(obj:T,keys: readonlyK[]):Pick<T,K>
Defined in: shared/utils/objectSafety.ts:180
Create a type-safe subset of an object with only specified keys.
Type Parametersโ
Tโ
T extends Record<PropertyKey, unknown>
Kโ
K extends string | number | symbol
Parametersโ
objโ
T
Source object
keysโ
readonly K[]
Keys to pick from the object
Returnsโ
Pick<T, K>
New object with only the specified keys
Exampleโ
const user = {
    id: 1,
    name: "John",
    email: "john@example.com",
    password: "secret",
};
const publicUser = safeObjectPick(user, [
    "id",
    "name",
    "email",
]);
// Type: { id: number; name: string; email: string; }