type Actual = {
a: () => 1;
x: string;
s: {
q: Nullable;
s: {
i: {
x: {
o: Maybe<Primitive>;
n: Falsy;
};
e: 'foo';
};
};
};
};
type Expected = {
a?: () => 1;
x?: string;
s?: {
q?: Nullable;
s?: {
i?: {
x?: {
o?: Maybe<Primitive>;
n?: Falsy;
};
e?: 'foo';
};
};
};
};
type T = DeepNotRequired<Actual>; // Result: Expected
Why not call it
DeepOptional
?Optional<T>
in this libraryOptional
represents a typeT
that can be eitherT
ornull
. So creatingDeepOptional
type would entail adding null to every property, which is not the intention here.DeepNotRequired<T>
turns all required keys in a given object (nested) to non required one. non required as in: marked with?
operator