I have the following type:
interface A {
p1: string
p2?: string
}
I would like to generate a sub-type B
with optional properties converted to nullable properties. Something equivalent to:
interface B {
p1: string
p2: string | null
}
I tried something like this:
type VuexPick<T, K extends keyof T> = {
[P in K]-?: T[P] extends undefined ? null : T[P];
};
type B = VuexPick<A, "p1" | "p2">;
But it doesn't work. Any idea?