Skip to content

Commit 56e6dee

Browse files
committed
Distributive conditional type applied to 'never' produces 'never'
1 parent daf3ed8 commit 56e6dee

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8229,8 +8229,8 @@ namespace ts {
82298229
const inferredTypes = map(inferences, inference => getTypeFromInference(inference) || emptyObjectType);
82308230
combinedMapper = combineTypeMappers(mapper, createTypeMapper(root.inferTypeParameters, inferredTypes));
82318231
}
8232-
// Return union of trueType and falseType for any and never since they match anything
8233-
if (checkType.flags & TypeFlags.Any || (checkType.flags & TypeFlags.Never && !(extendsType.flags & TypeFlags.Never))) {
8232+
// Return union of trueType and falseType for 'any' since it matches anything
8233+
if (checkType.flags & TypeFlags.Any) {
82348234
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);
82358235
}
82368236
// Instantiate the extends type including inferences for 'infer T' type parameters
@@ -8911,7 +8911,7 @@ namespace ts {
89118911
if (root.isDistributive) {
89128912
const checkType = <TypeParameter>root.checkType;
89138913
const instantiatedType = mapper(checkType);
8914-
if (checkType !== instantiatedType && instantiatedType.flags & TypeFlags.Union) {
8914+
if (checkType !== instantiatedType && instantiatedType.flags & (TypeFlags.Union | TypeFlags.Never)) {
89158915
return mapType(instantiatedType, t => getConditionalType(root, createReplacementMapper(checkType, t, mapper)));
89168916
}
89178917
}
@@ -12449,6 +12449,9 @@ namespace ts {
1244912449
// is a union type, the mapping function is applied to each constituent type and a union
1245012450
// of the resulting types is returned.
1245112451
function mapType(type: Type, mapper: (t: Type) => Type, noReductions?: boolean): Type {
12452+
if (type.flags & TypeFlags.Never) {
12453+
return type;
12454+
}
1245212455
if (!(type.flags & TypeFlags.Union)) {
1245312456
return mapper(type);
1245412457
}

0 commit comments

Comments
 (0)