Take the following deliberately simplified code example (my real use case is more complex, but the problem boils down to this):
type TArbitraryUnion = "a" | "b";
type TObjectWithGeneric<T> = {
prop: T;
};
type TTypeWithConditional<T> = T extends string
? TObjectWithGeneric<T>
: never;
type TTypeWithoutConditional<T> = TObjectWithGeneric<T>;
type TType1 = TTypeWithConditional<TArbitraryUnion>; // TObjectWithGeneric<"a"> | TObjectWithGeneric<"b">
type TType2 = TTypeWithoutConditional<TArbitraryUnion>; // {prop: TArbitraryUnion;}
TType1 ends up becoming a union of generics, whereas TType2 becomes a generic of the union.
Is there any way of creating the definition of TTypeWithConditional such that it becomes TObjectWithGeneric<"a" | "b"> instead of TObjectWithGeneric<"a"> | TObjectWithGeneric<"b">?
I'm struggling to understand why TType1 and TType2 are ending up as different types. Any help appreciated.