@@ -4618,12 +4618,14 @@ namespace ts {
4618
4618
const typeParameter = getTypeParameterFromMappedType(type);
4619
4619
const constraintType = getConstraintTypeFromMappedType(type);
4620
4620
const templateType = getTemplateTypeFromMappedType(type);
4621
- const modifiersType = getApparentType(getModifiersTypeFromMappedType(type));
4621
+ const modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
4622
4622
const templateReadonly = !!type.declaration.readonlyToken;
4623
4623
const templateOptional = !!type.declaration.questionToken;
4624
4624
if (type.declaration.typeParameter.constraint.kind === SyntaxKind.TypeOperator) {
4625
4625
// 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
+ }
4627
4629
if (getIndexInfoOfType(modifiersType, IndexKind.String)) {
4628
4630
addMemberForKeyType(stringType);
4629
4631
}
@@ -4638,7 +4640,7 @@ namespace ts {
4638
4640
}
4639
4641
setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined);
4640
4642
4641
- function addMemberForKeyType(t: Type) {
4643
+ function addMemberForKeyType(t: Type, propertySymbol?: Symbol ) {
4642
4644
// Create a mapper from T to the current iteration type constituent. Then, if the
4643
4645
// mapped type is itself an instantiated type, combine the iteration mapper with the
4644
4646
// instantiation mapper.
@@ -4654,6 +4656,9 @@ namespace ts {
4654
4656
const prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | (isOptional ? SymbolFlags.Optional : 0), propName);
4655
4657
prop.type = propType;
4656
4658
prop.isReadonly = templateReadonly || modifiersProp && isReadonlySymbol(modifiersProp);
4659
+ if (propertySymbol) {
4660
+ prop.mappedTypeOrigin = propertySymbol;
4661
+ }
4657
4662
members.set(propName, prop);
4658
4663
}
4659
4664
else if (t.flags & TypeFlags.String) {
@@ -20230,6 +20235,10 @@ namespace ts {
20230
20235
const links = symbol as SymbolLinks;
20231
20236
return [links.leftSpread, links.rightSpread];
20232
20237
}
20238
+ if ((symbol as SymbolLinks).mappedTypeOrigin) {
20239
+ return getRootSymbols((symbol as SymbolLinks).mappedTypeOrigin);
20240
+ }
20241
+
20233
20242
let target: Symbol;
20234
20243
let next = symbol;
20235
20244
while (next = getSymbolLinks(next).target) {
0 commit comments