You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type alias circularly references itself (5.4 regression)Β #58302
The issue is that following #56515 we perform constraint reduction on intersection types T & P or P & T, where T is a type parameter or indexed access type and P is a primitive type, the object type, or {}, reducing the intersection type to just T when the constraint of T fully encompasses P. For example, for a T extends string, the intersection T & string is reduced to just T. In the repro, we attempt to reduce the intersection string & {...}[keyof T], but resolving the constraint of {...}[keyof T] causes a circularity. It's unfortunate, but the price we have to pay to get the benefits of the feature.
I'd suggest rewriting the BooleanPaths type to this simpler formulation:
typeBooleanPaths<T,KextendskeyofT=keyofT>=Kextendsstring ?
T[K]extendsboolean ? K :
T[K]extendsobject ? `${K}.${BooleanPaths<T[K]>}` :
never :
never;
No circularity and handles both object and tuple types.
Activity
RyanCavanaugh commentedon Apr 24, 2024
Bisects to #56515
ahejlsberg commentedon May 6, 2024
The issue is that following #56515 we perform constraint reduction on intersection types
T & PorP & T, where T is a type parameter or indexed access type andPis a primitive type, theobjecttype, or{}, reducing the intersection type to justTwhen the constraint ofTfully encompassesP. For example, for aT extends string, the intersectionT & stringis reduced to justT. In the repro, we attempt to reduce the intersectionstring & {...}[keyof T], but resolving the constraint of{...}[keyof T]causes a circularity. It's unfortunate, but the price we have to pay to get the benefits of the feature.I'd suggest rewriting the
BooleanPathstype to this simpler formulation:No circularity and handles both object and tuple types.
typescript-bot commentedon May 9, 2024
This issue has been marked as "Design Limitation" and has seen no recent activity. It has been automatically closed for house-keeping purposes.