I'm new to typescript and I have a few interfaces defined like so:
interface A {
toRemove: string;
key1: "this1";
key2: number;
}
interface B {
toRemove: string;
key1: "this2";
key3: string;
}
And a union of both interfaces:
type C = A|B;
What I want to do is to remove the toRemove
key from both interfaces through C, something like this:
type CC = Omit<A, "toRemove">|Omit<B, "toRemove">;
But without having to omit the key from both interfaces. This would be ideal:
type CC = Omit<C, "toRemove">;
But, unfortunately, CC
will be of type Pick<A|B, "key1">
, where key1
is the key present in both interfaces.
In essence, what I'm trying to achieve is a type of "function" to transform:
A1|A2|...|An
into:
Omit<A1, K keyof A1>|Omit<A1, K keyof A2>|...|Omit<An, K keyof An>
I came across this answer https://stackoverflow.com/a/56297816/6520174 and I have a feeling that part of what I need is somewhere in there, but I don't really understand what's going on in that code.