Simplify or get constraint in distributive conditional type, but not both

This commit is contained in:
Anders Hejlsberg 2018-08-21 15:45:29 -07:00
parent 7c2644a676
commit 7740822d02

View file

@ -6921,7 +6921,8 @@ namespace ts {
// over the conditional type and possibly reduced. For example, 'T extends undefined ? never : T'
// removes 'undefined' from T.
if (type.root.isDistributive) {
const constraint = getConstraintOfType(getSimplifiedType(type.checkType));
const simplified = getSimplifiedType(type.checkType);
const constraint = simplified === type.checkType ? getConstraintOfType(simplified) : simplified;
if (constraint) {
const mapper = makeUnaryTypeMapper(type.root.checkType, constraint);
const instantiated = getConditionalTypeInstantiation(type, combineTypeMappers(mapper, type.mapper));