Skip to main content

PartialExcept<Original, Keys>

PartialExcept<Original, Keys> = Partial<Omit<Original, Keys>> & Required<Pick<Original, Keys>>

Creates a type where specified keys remain required while others become optional.


Type Parametersโ€‹

Original: Originalโ€‹

The original object type.

Keys: Keys extends keyof Originalโ€‹

The keys that should remain required.


Sinceโ€‹

1.0.0


Exampleโ€‹

type User = {
id: string;
name: string;
email?: string;
avatar?: string;
};

// PartialExcept<User, "id" | "name">
// Results in: { id: string; name: string; email?: string; avatar?: string; }
type UserUpdate = PartialExcept<User, "id" | "name">;

const update: UserUpdate = {
id: "123", // Required (kept as required)
name: "John", // Required (kept as required)
// email and avatar are optional (became optional)
};