/** * @description Constructs a type by picking all properties from T whose value type is assignable to P. * @template T The original object type. * @template P The target value type. */ type PickByType = { [K in keyof T as T[K] extends P ? K : never]: T[K]; }; // --- Usage Example --- interface ApiResponse { id: string; data: any; status: number; message: string; success: boolean; createdAt: Date; getName: () => string; } // Selects properties whose values are strings type StringProperties = PickByType; // Expected: { id: string; message: string; } const stringProps: StringProperties = { id: 'uuid-123', message: 'Operation successful', }; // Selects properties whose values are functions type FunctionProperties = PickByType; // Expected: { getName: () => string; } const funcProps: FunctionProperties = { getName: () => "Example", };