How to Make Specific Properties Required
Write a SetRequired helper in TypeScript 6 that makes chosen optional properties required while leaving the others alone, with checked examples.

Required<T> removes the ? from every property of a type. That is a blunt tool when only one or two fields need to become mandatory. A form draft has many optional fields, but after validation the id and email must exist. A configuration object may allow everything to be omitted by the user, yet the internal code that receives the merged result knows that port is always set. This post shows how to make specific properties required with a small generic type, why the obvious attempt has a trap, and how to keep the result readable in editor tooltips. The examples target TypeScript 6.x and behave the same in the native TypeScript 7 compiler. The reference for the mapped type modifiers used here is the mapped types chapter of the handbook.
The problem with Required
Start with a type where most fields are optional.
interface UserDraft {
id?: number;
email?: string;
name?: string;
newsletter?: boolean;
}
const saved: Required<UserDraft> = {
id: 1,
email: "[email protected]",
};The compiler wants every field, because Required removes the question mark from all of them.
draft.ts(8,7): error TS2739: Type '{ id: number; email: string; }' is missing the following properties from type 'Required<UserDraft>': name, newsletterYou wanted only id and email to be mandatory. The standard library has no helper for that, so you build one.
The intersection approach
The usual solution splits the type in two. One part holds the keys you want required, with the modifier removed. The other part holds the remaining keys unchanged. An intersection puts them back together.
export type SetRequired<T, K extends keyof T> = Omit<T, K> &
Required<Pick<T, K>>;Pick<T, K> selects the chosen keys, Required makes them mandatory, and Omit<T, K> keeps everything else exactly as it was, including its optional markers. The constraint K extends keyof T means a typo in the key list is an error instead of a silent no-op.
import type { SetRequired } from "./set-required.ts";
interface UserDraft {
id?: number;
email?: string;
name?: string;
newsletter?: boolean;
}
type SavedUser = SetRequired<UserDraft, "id" | "email">;
const saved: SavedUser = {
id: 1,
email: "[email protected]",
};
console.log(saved.email.toUpperCase());[email protected]The last line shows the benefit. Before, saved.email was string | undefined and toUpperCase needed a guard. Now the compiler knows it is a string. A missing key is rejected.
import type { SetRequired } from "./set-required.ts";
interface UserDraft {
id?: number;
email?: string;
}
const broken: SetRequired<UserDraft, "id" | "email"> = { id: 2 };missing.ts(8,7): error TS2741: Property 'email' is missing in type '{ id: number; }' but required in type 'Required<Pick<UserDraft, "id" | "email">>'.The tooltip problem
The intersection works, but hovering over SavedUser in an editor shows Omit<UserDraft, "id" | "email"> & Required<Pick<UserDraft, "id" | "email">>. That is accurate and unreadable. You can ask the compiler to flatten the result into one object type with a mapped type over the intersection.
type Simplify<T> = { [K in keyof T]: T[K] } & {};
export type SetRequired<T, K extends keyof T> = Simplify<
Omit<T, K> & Required<Pick<T, K>>
>;The mapped type { [K in keyof T]: T[K] } is homomorphic, so it keeps the optional and readonly modifiers of each property while collapsing the intersection into a single object. The trailing & {} is a long standing trick that nudges the editor to print the expanded shape instead of the alias name. If you do not care about tooltips, skip the helper. It changes display, not behavior.
After flattening, hovering shows the plain object with id: number, email: string, name?: string and newsletter?: boolean, which is what a reader wants.
A single mapped type alternative
You can express the same idea without an intersection, using key remapping with as. This is more compact, and it keeps one object type from the start.
export type SetRequired<T, K extends keyof T> = {
[P in keyof T as P extends K ? never : P]: T[P];
} & {
[P in K]-?: T[P];
};The first mapped type drops the chosen keys with as ... ? never, and the second adds them back with the -? modifier, which removes optionality. The result is the same intersection in disguise, so the tooltip issue remains, and you would still wrap it in Simplify. The version with Omit and Pick is shorter and more familiar to other readers, so prefer it unless you already use key remapping elsewhere.
There is one subtle detail in -?. It removes undefined from the property type only when undefined came from the optional modifier. If you declared email?: string | undefined and exactOptionalPropertyTypes is on, the explicit undefined stays in the type after -?. In practice, turn the option off or avoid writing | undefined on optional properties.
Using it at a validation boundary
The best place for this type is the output of a validator. The input is loose, the output is strict, and the function between them does the checking.
import type { SetRequired } from "./set-required.ts";
interface UserDraft {
id?: number;
email?: string;
name?: string;
}
type SavedUser = SetRequired<UserDraft, "id" | "email">;
function assertSaved(draft: UserDraft): asserts draft is SavedUser {
if (draft.id === undefined) throw new Error("id is required");
if (draft.email === undefined) throw new Error("email is required");
}
const draft: UserDraft = { id: 7, email: "[email protected]" };
assertSaved(draft);
console.log(draft.id + 1, draft.email.length);8 18After the call to assertSaved, the compiler narrows draft to SavedUser in the rest of the scope. The assertion function is where the trust is established, and from there the types carry it. If the check inside the function is wrong, the type is wrong, so keep these functions small and test them.
A related pattern is a type predicate that returns a boolean, which narrows only inside an if.
import type { SetRequired } from "./set-required.ts";
interface UserDraft {
id?: number;
email?: string;
}
function isSaved(d: UserDraft): d is SetRequired<UserDraft, "id" | "email"> {
return d.id !== undefined && d.email !== undefined;
}
const items: UserDraft[] = [{ id: 1, email: "[email protected]" }, { id: 2 }];
const ready = items.filter(isSaved);
console.log(ready.map((u) => u.email));[ '[email protected]' ]Because filter has an overload that accepts a type predicate, ready is typed as an array of the required shape, with no cast.
Pitfalls
The first pitfall is passing keys that are not optional. SetRequired<T, "name"> for a property that is already required is harmless, since Required has nothing to remove. The type does not error, which means it will not warn you when the plan changes.
The second is index signatures. keyof T for a type with a string index signature is string | number, so Omit collapses the type in surprising ways. Use SetRequired on object types with known keys.
The third is unions. Omit is not distributive, so applying SetRequired to a union type flattens it into one object and loses the discrimination. If you need to keep a union, distribute it yourself with a conditional type that takes each member in turn.
type SetRequiredEach<T, K extends PropertyKey> = T extends unknown
? Omit<T, K & keyof T> & Required<Pick<T, K & keyof T>>
: never;The fourth is readonly. Pick and Omit preserve readonly modifiers, so a readonly optional property becomes a readonly required one, which is normally what you want.
When not to use it
If your code needs the strict shape in many places, consider declaring a separate interface for the saved form and a function that converts a draft into it. A named type is easier to document than a computed one, and a conversion function makes the moment of validation visible in the code. The helper type is most useful when the two shapes differ by only a few keys and you do not want two declarations to drift apart.
Required keys that are computed
The key list does not have to be written by hand. If a type already groups the fields that must exist after a step, derive the list from it and the helper follows along.
import type { SetRequired } from "./set-required.ts";
interface Order {
id?: string;
total?: number;
note?: string;
}
type CheckoutKeys = "id" | "total";
type Paid = SetRequired<Order, CheckoutKeys>;
function receipt(order: Paid): string {
return `${order.id}: ${order.total.toFixed(2)}`;
}
console.log(receipt({ id: "A-100", total: 19.5 }));A-100: 19.50Naming the union once means a second function that needs the same guarantee reuses CheckoutKeys, and adding a key to the union updates every signature that mentions Paid. That is the real saving over a hand written second interface, where somebody forgets to update one copy.
A final caution about intent. A required property in a type is a promise to every caller, so make the promise at the narrowest point where it is true. Marking id required on the draft type itself would be wrong, because drafts genuinely have no id yet. The helper lets the draft stay honest and gives the later stage its own, stricter type.


