@@ -10196,6 +10196,7 @@ namespace ts {
10196
10196
function getSimplifiedType(type: Type, writing: boolean): Type {
10197
10197
return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(<IndexedAccessType>type, writing) :
10198
10198
type.flags & TypeFlags.Conditional ? getSimplifiedConditionalType(<ConditionalType>type, writing) :
10199
+ type.flags & TypeFlags.Substitution ? writing ? (<SubstitutionType>type).typeVariable : (<SubstitutionType>type).substitute :
10199
10200
type;
10200
10201
}
10201
10202
@@ -10260,10 +10261,10 @@ namespace ts {
10260
10261
}
10261
10262
10262
10263
function getSimplifiedConditionalType(type: ConditionalType, writing: boolean) {
10263
- const falseType = getFalseTypeFromConditionalType(type);
10264
- const trueType = getTrueTypeFromConditionalType(type);
10265
10264
const checkType = type.checkType;
10266
10265
const extendsType = type.extendsType;
10266
+ const trueType = getTrueTypeFromConditionalType(type);
10267
+ const falseType = getFalseTypeFromConditionalType(type);
10267
10268
// Simplifications for types of the form `T extends U ? T : never` and `T extends U ? never : T`.
10268
10269
if (falseType.flags & TypeFlags.Never && getActualTypeVariable(trueType) === getActualTypeVariable(checkType)) {
10269
10270
if (checkType.flags & TypeFlags.Any || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(extendsType))) { // Always true
@@ -10281,10 +10282,16 @@ namespace ts {
10281
10282
return getSimplifiedType(falseType, writing);
10282
10283
}
10283
10284
}
10284
-
10285
10285
return type;
10286
10286
}
10287
10287
10288
+ /**
10289
+ * Invokes union simplification logic to determine if an intersection is considered empty as a union constituent
10290
+ */
10291
+ function isIntersectionEmpty(type1: Type, type2: Type) {
10292
+ return !!(getUnionType([intersectTypes(type1, type2), neverType]).flags & TypeFlags.Never);
10293
+ }
10294
+
10288
10295
function substituteIndexedMappedType(objectType: MappedType, index: Type) {
10289
10296
const mapper = createTypeMapper([getTypeParameterFromMappedType(objectType)], [index]);
10290
10297
const templateMapper = combineTypeMappers(objectType.mapper, mapper);
@@ -10391,36 +10398,12 @@ namespace ts {
10391
10398
return type;
10392
10399
}
10393
10400
10394
- /**
10395
- * Invokes union simplification logic to determine if an intersection is considered empty as a union constituent
10396
- */
10397
- function isIntersectionEmpty(type1: Type, type2: Type) {
10398
- return !!(getUnionType([intersectTypes(type1, type2), neverType]).flags & TypeFlags.Never);
10399
- }
10400
-
10401
10401
function getConditionalType(root: ConditionalRoot, mapper: TypeMapper | undefined): Type {
10402
10402
const checkType = instantiateType(root.checkType, mapper);
10403
10403
const extendsType = instantiateType(root.extendsType, mapper);
10404
10404
if (checkType === wildcardType || extendsType === wildcardType) {
10405
10405
return wildcardType;
10406
10406
}
10407
- // Simplifications for types of the form `T extends U ? T : never` and `T extends U ? never : T`.
10408
- if (root.falseType.flags & TypeFlags.Never && getActualTypeVariable(root.trueType) === getActualTypeVariable(root.checkType)) {
10409
- if (checkType.flags & TypeFlags.Any || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(extendsType))) { // Always true
10410
- return checkType;
10411
- }
10412
- else if (isIntersectionEmpty(checkType, extendsType)) { // Always false
10413
- return neverType;
10414
- }
10415
- }
10416
- else if (root.trueType.flags & TypeFlags.Never && getActualTypeVariable(root.falseType) === getActualTypeVariable(root.checkType)) {
10417
- if (!(checkType.flags & TypeFlags.Any) && isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(extendsType))) { // Always true
10418
- return neverType;
10419
- }
10420
- else if (checkType.flags & TypeFlags.Any || isIntersectionEmpty(checkType, extendsType)) { // Always false
10421
- return checkType;
10422
- }
10423
- }
10424
10407
const checkTypeInstantiable = maybeTypeOfKind(checkType, TypeFlags.Instantiable | TypeFlags.GenericMappedType);
10425
10408
let combinedMapper: TypeMapper | undefined;
10426
10409
if (root.inferTypeParameters) {
@@ -10461,10 +10444,6 @@ namespace ts {
10461
10444
}
10462
10445
}
10463
10446
// Return a deferred type for a check that is neither definitely true nor definitely false
10464
- return getDeferredConditionalType(root, mapper, combinedMapper, checkType, extendsType);
10465
- }
10466
-
10467
- function getDeferredConditionalType(root: ConditionalRoot, mapper: TypeMapper | undefined, combinedMapper: TypeMapper | undefined, checkType: Type, extendsType: Type) {
10468
10447
const erasedCheckType = getActualTypeVariable(checkType);
10469
10448
const result = <ConditionalType>createType(TypeFlags.Conditional);
10470
10449
result.root = root;
@@ -12453,12 +12432,6 @@ namespace ts {
12453
12432
if (isFreshLiteralType(target)) {
12454
12433
target = (<FreshableType>target).regularType;
12455
12434
}
12456
- if (source.flags & TypeFlags.Substitution) {
12457
- source = (<SubstitutionType>source).substitute;
12458
- }
12459
- if (target.flags & TypeFlags.Substitution) {
12460
- target = (<SubstitutionType>target).typeVariable;
12461
- }
12462
12435
if (source.flags & TypeFlags.Simplifiable) {
12463
12436
source = getSimplifiedType(source, /*writing*/ false);
12464
12437
}
0 commit comments