Type Intersection incorrect for optional parameters in functions with exactOptionalPropertyTypes: true
. undefined
type is flip based off Intersection types
#58174
Labels
Milestone
This issue seem to only be related when
exactOptionalPropertyTypes: true
option is setIf I have:
Consider
fnA
, since a property that is optional may beundefined
when it is called it makes sense thatundefined
is added to the type, as is in the case in fnA// disabled: boolean | undefined
. (fnB example added for completeness).Now consider
fnAB
with the intersection typeAB
, property disabled type should also be// disabled: boolean | undefined
but it is not, instead it is// disabled: boolean
Finally
fnAC
with the intersection typeAC
, the property disabled type is now correct being// disabled: boolean | undefined
.It seems like in the above example with
fnAB
(intersection of AB) theundefined
's are canceling out sinceundefined
is added with the?
optional parameter. A similar issue can be observed with two undefined such as{ disabled?: boolean | undefined; } && { disabled?: boolean | undefined; }
would result in//disabled: boolean
It's worth noting this doesn't seem to only be limited to function parameter de-structuring since a similar issue is seen in:
When
exactOptionalPropertyTypes: false
property disabled is alwaysdisabled //disabled: boolean | undefined
which is correctThe text was updated successfully, but these errors were encountered: