PartialPick

by default, the partial makes everything optional, but you can use this type to make a partial pick of a type.

export type PartialPick<T, key extends keyof T> = Partial<Pick<T, key>> &
  Omit<T, key>;

Installation

pnpm dlx shadcn@latest add https://mhl5.vercel.app/r/PartialPick.json

Usage

import { PartialPick } from "@/types/PartialPick";

type User = {
  id: number;
  email: string;
  name: string;
  created_at: string;
  updated_at: string;
};

type PartialUser = PartialPick<User, "id" | "email">;

// Equivalent to:
type PartialUser = {
  id?: number;
  email?: string;
  name: string;
  created_at: string;
  updated_at: string;
};