@@ -4618,12 +4618,14 @@ namespace ts {
46184618 const typeParameter = getTypeParameterFromMappedType(type);
46194619 const constraintType = getConstraintTypeFromMappedType(type);
46204620 const templateType = getTemplateTypeFromMappedType(type);
4621- const modifiersType = getApparentType(getModifiersTypeFromMappedType(type));
4621+ const modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
46224622 const templateReadonly = !!type.declaration.readonlyToken;
46234623 const templateOptional = !!type.declaration.questionToken;
46244624 if (type.declaration.typeParameter.constraint.kind === SyntaxKind.TypeOperator) {
46254625 // We have a { [P in keyof T]: X }
4626- forEachType(getLiteralTypeFromPropertyNames(modifiersType), addMemberForKeyType);
4626+ for (const propertySymbol of getPropertiesOfType(modifiersType)) {
4627+ addMemberForKeyType(getLiteralTypeFromPropertyName(propertySymbol), propertySymbol);
4628+ }
46274629 if (getIndexInfoOfType(modifiersType, IndexKind.String)) {
46284630 addMemberForKeyType(stringType);
46294631 }
@@ -4638,7 +4640,7 @@ namespace ts {
46384640 }
46394641 setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined);
46404642
4641- function addMemberForKeyType(t: Type) {
4643+ function addMemberForKeyType(t: Type, propertySymbol?: Symbol ) {
46424644 // Create a mapper from T to the current iteration type constituent. Then, if the
46434645 // mapped type is itself an instantiated type, combine the iteration mapper with the
46444646 // instantiation mapper.
@@ -4654,6 +4656,9 @@ namespace ts {
46544656 const prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | (isOptional ? SymbolFlags.Optional : 0), propName);
46554657 prop.type = propType;
46564658 prop.isReadonly = templateReadonly || modifiersProp && isReadonlySymbol(modifiersProp);
4659+ if (propertySymbol) {
4660+ prop.mappedTypeOrigin = propertySymbol;
4661+ }
46574662 members.set(propName, prop);
46584663 }
46594664 else if (t.flags & TypeFlags.String) {
@@ -20233,6 +20238,10 @@ namespace ts {
2023320238 const links = symbol as SymbolLinks;
2023420239 return [links.leftSpread, links.rightSpread];
2023520240 }
20241+ if ((symbol as SymbolLinks).mappedTypeOrigin) {
20242+ return getRootSymbols((symbol as SymbolLinks).mappedTypeOrigin);
20243+ }
20244+
2023620245 let target: Symbol;
2023720246 let next = symbol;
2023820247 while (next = getSymbolLinks(next).target) {
0 commit comments