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
Conditional types wrongly work with indexed access and object type (regression) #23800
The immediate cause of this is #23768. However, it just exposes indexed access types to an issue that already exists with regular type parameters:
functionfoo<T,U>(x: T){leta: object=x;// Error as expectedletb: U|object=x;// No error!}
The problem is caused by some logic in structuredTypeRelatedTo that specifically excludes checking the default {} constraint of an unconstrained type parameter against a target type of object. However, that logic doesn't kick in when the target is a union type that includes object.
Instead of attempting to exclude cases, when the source is an unconstrained type variable I think we need to check if the target is an empty object type or a union containing an empty object type.
Activity
mhegazy commentedon May 1, 2018
I see both as
{ a: 0 }on latest and on 2.8.3 (playground)mhegazy commentedon May 1, 2018
never mind.. looks like we broke it yesterday.
ahejlsberg commentedon May 1, 2018
The immediate cause of this is #23768. However, it just exposes indexed access types to an issue that already exists with regular type parameters:
The problem is caused by some logic in
structuredTypeRelatedTothat specifically excludes checking the default{}constraint of an unconstrained type parameter against a target type ofobject. However, that logic doesn't kick in when the target is a union type that includesobject.Instead of attempting to exclude cases, when the source is an unconstrained type variable I think we need to check if the target is an empty object type or a union containing an empty object type.