TypeScript generics with conditional types causing circular type errors in a complex utility type
I'm converting an old project and I just started working with I'm working with a frustrating scenario while trying to define a utility type in TypeScript that uses generics and conditional types... The type is intended to transform an object type based on whether its properties are of a certain shape. However, when I attempt to use this utility type, I get circular type errors. Hereβs what I have so far: ```typescript type PropertyShape<T> = T extends { a: infer A, b: infer B } ? A | B : never; type Transform<T> = { [K in keyof T]: T[K] extends object ? PropertyShape<T[K]> : T[K]; }; type Example = { item1: { a: number, b: string }; item2: { a: boolean, b: number }; item3: string; }; type Transformed = Transform<Example>; ``` When I try to compile this, I get the following behavior: ``` Type alias 'Transform' circularly references itself. ``` I've also tried breaking down the utility type into smaller pieces, but it doesn't seem to resolve the circular dependency. I suspect the scenario might be related to how I'm using `infer` within the conditional type, but Iβm not sure how to address this without losing the intended functionality. I've checked the TypeScript version I'm using, which is 4.5.2. Any guidance on how I can refactor this to avoid the circular type behavior while still achieving the transformation I need would be greatly appreciated! I appreciate any insights! I appreciate any insights! Is there a simpler solution I'm overlooking?