Type Alias RequiredNonOptional<T>

RequiredNonOptional<T>: T extends object
    ? {
        [P in keyof T]-?: NonOptional<T[P]>
    }
    : T

Converts a type T that may have optional properties into a type T with only required properties (e.g. undefined values are not allowed). Explicit nulls in value unions will still be possible. This is similar to the Required builtin mapped type, but also subtracts undefined from value union types as well as the optional property declaration.

type Foo = { bar?: string | undefined | null };
type RequiredNonOptionalFoo = RequiredNonOptional<Foo>;
// RequiredNonOptionalFoo -> { bar: string | null };

Type Parameters

  • T