I've got a bunch of generated types (via GraphQL codegen) that look like this:
type X = {
a?: Maybe<number>
b?: Maybe<Array<MyType> | MyType>
c?: Maybe<MyType2>
d?: Maybe<Array<MyType3> | MyType3>
}
// Maybe is:
// type Maybe<T> = T | null | undefined;
For fields b
and d
, the codegen does the right thing according to GraphQL spec (see this issue) but in my specific codebase, I need to transform all the types to basically this:
type X2 = {
a?: Maybe<number>
b?: Maybe<Array<MyType>>
c?: Maybe<MyType2>
d?: Maybe<Array<MyType3>>
}
How to write a type utility that does this?
(Manually, it would be done like this:)
type X2 = Omit<X, 'b' | 'd'> & {
b?: Maybe<Array<MyType>>;
d?: Maybe<Array<MyType3>>;
};
MyType
s. I don't want to write something up and find out thatMyType3 extends Array<MyType2>
or something weird like that.