Skip to content

Commit a437c0a

Browse files
committed
Fix homomorphic type check in instantiateMappedType
1 parent 69e0677 commit a437c0a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6628,17 +6628,19 @@ namespace ts {
66286628
const constraintType = getConstraintTypeFromMappedType(type);
66296629
if (constraintType.flags & TypeFlags.Index) {
66306630
const typeVariable = (<IndexType>constraintType).type;
6631-
const mappedTypeVariable = instantiateType(typeVariable, mapper);
6632-
if (typeVariable !== mappedTypeVariable) {
6633-
return mapType(mappedTypeVariable, t => {
6634-
if (isMappableType(t)) {
6635-
const replacementMapper = createUnaryTypeMapper(typeVariable, t);
6636-
const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper);
6637-
combinedMapper.mappedTypes = mapper.mappedTypes;
6638-
return instantiateMappedObjectType(type, combinedMapper);
6639-
}
6640-
return t;
6641-
});
6631+
if (typeVariable.flags & TypeFlags.TypeParameter) {
6632+
const mappedTypeVariable = instantiateType(typeVariable, mapper);
6633+
if (typeVariable !== mappedTypeVariable) {
6634+
return mapType(mappedTypeVariable, t => {
6635+
if (isMappableType(t)) {
6636+
const replacementMapper = createUnaryTypeMapper(typeVariable, t);
6637+
const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper);
6638+
combinedMapper.mappedTypes = mapper.mappedTypes;
6639+
return instantiateMappedObjectType(type, combinedMapper);
6640+
}
6641+
return t;
6642+
});
6643+
}
66426644
}
66436645
}
66446646
return instantiateMappedObjectType(type, mapper);

0 commit comments

Comments
 (0)