Type alias MakeRequired<T, K>

MakeRequired<T, K>: Simplify<Required<Pick<T, RequiredKeys<T> | K>> & Partial<Pick<T, Exclude<NonRequiredKeys<T>, K>>>>

Constructs a new type from T where the specified keys K become required, while all other keys preserve their original modifiers.

This version correctly handles keys that were originally optional by using Required<Pick<...>>, which removes the optional modifier in the same style as TypeScript's built-in Required<T>.

Type Parameters

  • T extends object

    The original object type.

  • K extends keyof T

    The keys within T that should be made required.

Example

type Config = {
host?: string;
port?: number;
secure: boolean;
};

type Result = MakeRequired<Config, 'host' | 'port'>;

// {
// host: string;
// port: number;
// secure: boolean;
// }

Example

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

type Result = MakeRequired<User, 'id'>;

// {
// id: string;
// name: string;
// email?: string;
// }