undefined vs optional
Is there a way to make this utility type work for optional keys?
I would want the optional key to be
I would want the optional key to be
string | null as wellstring | nulltype UndefinedToNull<T> = T extends undefined
? null
: T extends Date
? T
: {
[K in keyof T]: UndefinedToNull<T[K]>;
};
type A = {
foo?: string;
bar: string | undefined;
};
// type B = {
// foo?: string | null | undefined;
// bar: string | null;
// }
type B = UndefinedToNull<A>;