From a437c0a6893cb1625123c1b482ba934391af2a80 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 30 Dec 2016 18:27:38 -0800 Subject: [PATCH] Fix homomorphic type check in instantiateMappedType --- src/compiler/checker.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 22dec25324d..38feb249b76 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6628,17 +6628,19 @@ namespace ts { const constraintType = getConstraintTypeFromMappedType(type); if (constraintType.flags & TypeFlags.Index) { const typeVariable = (constraintType).type; - const mappedTypeVariable = instantiateType(typeVariable, mapper); - if (typeVariable !== mappedTypeVariable) { - return mapType(mappedTypeVariable, t => { - if (isMappableType(t)) { - const replacementMapper = createUnaryTypeMapper(typeVariable, t); - const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper); - combinedMapper.mappedTypes = mapper.mappedTypes; - return instantiateMappedObjectType(type, combinedMapper); - } - return t; - }); + if (typeVariable.flags & TypeFlags.TypeParameter) { + const mappedTypeVariable = instantiateType(typeVariable, mapper); + if (typeVariable !== mappedTypeVariable) { + return mapType(mappedTypeVariable, t => { + if (isMappableType(t)) { + const replacementMapper = createUnaryTypeMapper(typeVariable, t); + const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper); + combinedMapper.mappedTypes = mapper.mappedTypes; + return instantiateMappedObjectType(type, combinedMapper); + } + return t; + }); + } } } return instantiateMappedObjectType(type, mapper);