ts-type-forge
    Preparing search index...

    Type Alias OptionalKeys<R>

    OptionalKeys: PickUndefined<MapToNever<R>>

    Extracts keys from a record R that are explicitly marked as optional using the ? modifier. It works by creating a mapped type where all values are never and then using PickUndefined to find keys where undefined is assignable (which is true only for optional properties in this context).

    Type Parameters

    A union of keys that are optional in R.

    type K = OptionalKeys<{
    a?: 0; // optional
    b?: 0 | undefined; // optional
    c?: undefined; // optional
    d: 0; // required
    e: undefined; // required, value is undefined
    f: 0 | undefined; // required, value includes undefined
    }>; // 'a' | 'b' | 'c'