diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c9243e811b81d..75df0d653be0d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15638,14 +15638,16 @@ namespace ts { return result; } + function isDistributionDependent(root: ConditionalRoot) { + return root.isDistributive && ( + isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.trueType) || + isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.falseType)); + } + function getTypeFromConditionalTypeNode(node: ConditionalTypeNode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { const checkType = getTypeFromTypeNode(node.checkType); - const isDistributive = !!(checkType.flags & TypeFlags.TypeParameter); - const isDistributionDependent = isDistributive && ( - isTypeParameterPossiblyReferenced(checkType as TypeParameter, node.trueType) || - isTypeParameterPossiblyReferenced(checkType as TypeParameter, node.falseType)); const aliasSymbol = getAliasSymbolForTypeNode(node); const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol); const allOuterTypeParameters = getOuterTypeParameters(node, /*includeThisTypes*/ true); @@ -15654,8 +15656,7 @@ namespace ts { node, checkType, extendsType: getTypeFromTypeNode(node.extendsType), - isDistributive, - isDistributionDependent, + isDistributive: !!(checkType.flags & TypeFlags.TypeParameter), inferTypeParameters: getInferTypeParameters(node), outerTypeParameters, instantiations: undefined, @@ -19032,7 +19033,7 @@ namespace ts { // We check for a relationship to a conditional type target only when the conditional type has no // 'infer' positions and is not distributive or is distributive but doesn't reference the check type // parameter in either of the result types. - if (!c.root.inferTypeParameters && !c.root.isDistributionDependent) { + if (!c.root.inferTypeParameters && !isDistributionDependent(c.root)) { // Check if the conditional is always true or always false but still deferred for distribution purposes. const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); const skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1343e1859ae31..6c7cb7b5187c6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5648,7 +5648,6 @@ namespace ts { checkType: Type; extendsType: Type; isDistributive: boolean; - isDistributionDependent: boolean; inferTypeParameters?: TypeParameter[]; outerTypeParameters?: TypeParameter[]; instantiations?: Map; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index e1512586cff46..116be4316f918 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2747,7 +2747,6 @@ declare namespace ts { checkType: Type; extendsType: Type; isDistributive: boolean; - isDistributionDependent: boolean; inferTypeParameters?: TypeParameter[]; outerTypeParameters?: TypeParameter[]; instantiations?: Map; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f93ca902bbf07..56d764c664c5d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2747,7 +2747,6 @@ declare namespace ts { checkType: Type; extendsType: Type; isDistributive: boolean; - isDistributionDependent: boolean; inferTypeParameters?: TypeParameter[]; outerTypeParameters?: TypeParameter[]; instantiations?: Map;