/** * Object utility types for TypeScript * @module ObjectTypes */ /** * Makes all properties in T optional * @template T - The type to make optional * @example * ```typescript * interface User { * id: number; * name: string; * email: string; * } * * type PartialUser = Partial; * // Result: { id?: number; name?: string; email?: string; } * ``` */ export type Partial = { [P in keyof T]?: T[P]; }; /** * Makes all properties in T required * @template T - The type to make required * @example * ```typescript * interface User { * id?: number; * name?: string; * email?: string; * } * * type RequiredUser = Required; * // Result: { id: number; name: string; email: string; } * ``` */ export type Required = { [P in keyof T]-?: T[P]; }; /** * Makes all properties in T readonly * @template T - The type to make readonly * @example * ```typescript * interface User { * id: number; * name: string; * email: string; * } * * type ReadonlyUser = Readonly; * // Result: { readonly id: number; readonly name: string; readonly email: string; } * ``` */ export type Readonly = { readonly [P in keyof T]: T[P]; }; /** * Picks a set of properties from T * @template T - The source type * @template K - The keys to pick * @example * ```typescript * interface User { * id: number; * name: string; * email: string; * password: string; * } * * type UserPublic = Pick; * // Result: { id: number; name: string; email: string; } * ``` */ export type Pick = { [P in K]: T[P]; }; /** * Omits a set of properties from T * @template T - The source type * @template K - The keys to omit * @example * ```typescript * interface User { * id: number; * name: string; * email: string; * password: string; * } * * type UserWithoutPassword = Omit; * // Result: { id: number; name: string; email: string; } * ``` */ export type Omit = Pick>; /** * Creates a type with a set of properties K of type T * @template K - The keys * @template T - The type for the properties * @example * ```typescript * type UserRoles = Record<'admin' | 'user' | 'guest', boolean>; * // Result: { admin: boolean; user: boolean; guest: boolean; } * ``` */ export type Record = { [P in K]: T; }; /** * Extracts the type of a property from an object type * @template T - The object type * @template K - The property key * @example * ```typescript * interface User { * id: number; * name: string; * profile: { age: number; city: string; }; * } * * type UserName = ExtractProperty; // string * type UserProfile = ExtractProperty; // { age: number; city: string; } * ``` */ export type ExtractProperty = T[K]; /** * Makes specific properties optional in T * @template T - The source type * @template K - The keys to make optional * @example * ```typescript * interface User { * id: number; * name: string; * email: string; * phone?: string; * } * * type UserWithOptionalContact = PartialBy; * // Result: { id: number; name: string; email?: string; phone?: string; } * ``` */ export type PartialBy = Omit & Partial>; /** * Makes specific properties required in T * @template T - The source type * @template K - The keys to make required * @example * ```typescript * interface User { * id?: number; * name?: string; * email?: string; * phone?: string; * } * * type UserWithRequiredId = RequiredBy; * // Result: { id: number; name?: string; email?: string; phone?: string; } * ``` */ export type RequiredBy = Omit & Required>; /** * Creates a type with all properties from T except those in K * @template T - The source type * @template K - The keys to exclude * @example * ```typescript * interface User { * id: number; * name: string; * email: string; * password: string; * createdAt: Date; * } * * type UserWithoutSensitive = ExcludeKeys; * // Result: { id: number; name: string; email: string; } * ``` */ export type ExcludeKeys = Pick>; /** * Creates a type with only the specified keys from T * @template T - The source type * @template K - The keys to include * @example * ```typescript * interface User { * id: number; * name: string; * email: string; * password: string; * createdAt: Date; * } * * type UserBasic = IncludeKeys; * // Result: { id: number; name: string; email: string; } * ``` */ export type IncludeKeys = Pick; //# sourceMappingURL=object.d.ts.map