Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index signatures for symbols and template literal strings #44512

Merged
merged 59 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
95dc813
Switch index signature storage to 'indexInfos: IndexInfo[]' property
ahejlsberg May 31, 2021
fc107dc
Accept new baselines
ahejlsberg May 31, 2021
60cff44
Remove another usage of IndexKind enum
ahejlsberg May 31, 2021
9900302
Update getIndexedAccessType and resolveMappedTypeMembers
ahejlsberg Jun 1, 2021
f27bea2
Accept new baselines
ahejlsberg Jun 1, 2021
a064ec1
Update grammar checking for index signatures
ahejlsberg Jun 2, 2021
01cb825
Accept new baselines
ahejlsberg Jun 2, 2021
8622ae6
Consider all index signatures in mapped types and union types
ahejlsberg Jun 2, 2021
7285cb9
Accept new baselines
ahejlsberg Jun 2, 2021
4bd05bc
Update getIndexType
ahejlsberg Jun 2, 2021
a91782f
Accept new baselines
ahejlsberg Jun 2, 2021
730ded4
Intersect multiple applicable index signatures
ahejlsberg Jun 3, 2021
c6cc9a1
Use getApplicableIndexInfo instead of hardwired string/number handling
ahejlsberg Jun 3, 2021
bed9264
Update index signature relationship checking
ahejlsberg Jun 4, 2021
cf0b614
Report type for which index signature is missing
ahejlsberg Jun 4, 2021
2c0bf2b
Report type for which index signature is missing
ahejlsberg Jun 4, 2021
041a12f
Accept new baselines
ahejlsberg Jun 4, 2021
61297e3
Make 'number' index signatures consistently apply to numeric strings
ahejlsberg Jun 5, 2021
7f0f4c3
Accept new baselines
ahejlsberg Jun 5, 2021
9442790
Update fourslash test
ahejlsberg Jun 5, 2021
f96f513
Revise index constraint checking
ahejlsberg Jun 6, 2021
91e3546
Accept new baselines
ahejlsberg Jun 6, 2021
f24a654
Update error messages
ahejlsberg Jun 6, 2021
f2a20cc
Accept new baselines
ahejlsberg Jun 6, 2021
135e181
Update type inference from index signatures
ahejlsberg Jun 6, 2021
0c27c9c
Update isKnownProperty
ahejlsberg Jun 6, 2021
b8ac093
Update contextual typing based on index signatures
ahejlsberg Jun 7, 2021
b2a014c
Accept new baselines
ahejlsberg Jun 7, 2021
ab96d54
Support union types in index signature declarations
ahejlsberg Jun 7, 2021
bed7008
Accept new baselines
ahejlsberg Jun 7, 2021
a880248
Check duplicate index signatures / remove redundant template literals…
ahejlsberg Jun 7, 2021
dccec9a
Accept new baselines
ahejlsberg Jun 7, 2021
535c5e3
Include key type in diagnostic / check symbol-named properties
ahejlsberg Jun 8, 2021
cf8b547
Accept new baselines
ahejlsberg Jun 8, 2021
077c960
Minor fix
ahejlsberg Jun 8, 2021
96390ca
Add tests
ahejlsberg Jun 8, 2021
b7c9038
Accept new baselines
ahejlsberg Jun 8, 2021
2039e04
Merge branch 'main' into moreIndexSignatures
ahejlsberg Jun 8, 2021
a92a41b
Add optimized findApplicableIndexInfoForName
ahejlsberg Jun 9, 2021
8dd8e38
Accept new baselines
ahejlsberg Jun 9, 2021
9e3f8ce
Another place we don't need to obtain literal type for property name
ahejlsberg Jun 9, 2021
a98ff6d
Accept new baselines
ahejlsberg Jun 9, 2021
8b2098d
Don't create literal types that are going to be discarded
ahejlsberg Jun 10, 2021
d357fa0
Individual maps for string, number, bigint, and enum literal types
ahejlsberg Jun 10, 2021
cfd67e6
Remove ineffective optimizations
ahejlsberg Jun 11, 2021
e807041
Accept new baselines
ahejlsberg Jun 11, 2021
5354b39
Permit intersections as key types in index signatures
ahejlsberg Jun 15, 2021
4d0a3e0
Index expression in element access is template literal context
ahejlsberg Jun 15, 2021
00c7549
Add tests
ahejlsberg Jun 15, 2021
7a5ec8d
Accept new baselines
ahejlsberg Jun 15, 2021
c27ba9b
Merge branch 'main' into moreIndexSignatures
ahejlsberg Jun 15, 2021
bf633d8
Symbol index signatures from object literals with computed symbol pro…
ahejlsberg Jun 18, 2021
5baae83
Accept new baselines
ahejlsberg Jun 18, 2021
2f4c967
Add more tests
ahejlsberg Jun 18, 2021
f3897c1
Accept new baselines
ahejlsberg Jun 18, 2021
ef47fa1
Merge branch 'main' into moreIndexSignatures
ahejlsberg Jun 18, 2021
fbffa7c
Implement Go To Definition for all applicable index signatures
ahejlsberg Jun 19, 2021
128e125
Add fourslash test
ahejlsberg Jun 19, 2021
1e376a5
Accept new API baselines
ahejlsberg Jun 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,171 changes: 558 additions & 613 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

36 changes: 14 additions & 22 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@
"category": "Error",
"code": 1022
},
"An index signature parameter type must be either 'string' or 'number'.": {
"category": "Error",
"code": 1023
},
"'readonly' modifier can only appear on a property declaration or index signature.": {
"category": "Error",
"code": 1024
Expand Down Expand Up @@ -891,6 +887,10 @@
"category": "Error",
"code": 1267
},
"An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.": {
"category": "Error",
"code": 1268
},

"'with' statements are not allowed in an async function block.": {
"category": "Error",
Expand Down Expand Up @@ -996,11 +996,7 @@
"category": "Error",
"code": 1335
},
"An index signature parameter type cannot be a type alias. Consider writing '[{0}: {1}]: {2}' instead.": {
"category": "Error",
"code": 1336
},
"An index signature parameter type cannot be a union type. Consider using a mapped object type instead.": {
"An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.": {
"category": "Error",
"code": 1337
},
Expand Down Expand Up @@ -1518,11 +1514,11 @@
"category": "Error",
"code": 2328
},
"Index signature is missing in type '{0}'.": {
"Index signature for type '{0}' is missing in type '{1}'.": {
"category": "Error",
"code": 2329
},
"Index signatures are incompatible.": {
"'{0}' and '{1}' index signatures are incompatible.": {
"category": "Error",
"code": 2330
},
Expand Down Expand Up @@ -1698,14 +1694,10 @@
"category": "Error",
"code": 2373
},
"Duplicate string index signature.": {
"Duplicate index signature for type '{0}'.": {
"category": "Error",
"code": 2374
},
"Duplicate number index signature.": {
"category": "Error",
"code": 2375
},
"A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.": {
"category": "Error",
"code": 2376
Expand Down Expand Up @@ -1842,15 +1834,11 @@
"category": "Error",
"code": 2410
},
"Property '{0}' of type '{1}' is not assignable to string index type '{2}'.": {
"Property '{0}' of type '{1}' is not assignable to '{2}' index type '{3}'.": {
"category": "Error",
"code": 2411
},
"Property '{0}' of type '{1}' is not assignable to numeric index type '{2}'.": {
"category": "Error",
"code": 2412
},
"Numeric index type '{0}' is not assignable to string index type '{1}'.": {
"'{0}' index type '{1}' is not assignable to '{2}' index type '{3}'.": {
"category": "Error",
"code": 2413
},
Expand Down Expand Up @@ -2690,6 +2678,10 @@
"category": "Error",
"code": 2633
},
"'{0}' index signatures are incompatible.": {
"category": "Error",
"code": 2634
},

"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
"category": "Error",
Expand Down
11 changes: 4 additions & 7 deletions src/compiler/symbolWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace ts {
resolveStructuredTypeMembers: (type: ObjectType) => ResolvedType,
getTypeOfSymbol: (sym: Symbol) => Type,
getResolvedSymbol: (node: Node) => Symbol,
getIndexTypeOfStructuredType: (type: Type, kind: IndexKind) => Type | undefined,
getConstraintOfTypeParameter: (typeParameter: TypeParameter) => Type | undefined,
getFirstIdentifier: (node: EntityNameOrEntityNameExpression) => Identifier,
getTypeArguments: (type: TypeReference) => readonly Type[]) {
Expand Down Expand Up @@ -140,13 +139,11 @@ namespace ts {
}

function visitObjectType(type: ObjectType): void {
const stringIndexType = getIndexTypeOfStructuredType(type, IndexKind.String);
visitType(stringIndexType);
const numberIndexType = getIndexTypeOfStructuredType(type, IndexKind.Number);
visitType(numberIndexType);

// The two checks above *should* have already resolved the type (if needed), so this should be cached
const resolved = resolveStructuredTypeMembers(type);
for (const info of resolved.indexInfos) {
visitType(info.keyType);
visitType(info.type);
}
for (const signature of resolved.callSignatures) {
visitSignature(signature);
}
Expand Down
18 changes: 10 additions & 8 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4088,6 +4088,7 @@ namespace ts {
getPrivateIdentifierPropertyOfType(leftType: Type, name: string, location: Node): Symbol | undefined;
/* @internal */ getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined;
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
getIndexInfosOfType(type: Type): readonly IndexInfo[];
getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[];
getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined;
getBaseTypes(type: InterfaceType): BaseType[];
Expand Down Expand Up @@ -4117,8 +4118,8 @@ namespace ts {
signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): SignatureDeclaration & {typeArguments?: NodeArray<TypeNode>} | undefined;
/* @internal */ signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined, tracker?: SymbolTracker): SignatureDeclaration & {typeArguments?: NodeArray<TypeNode>} | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
/** Note that the resulting nodes cannot be checked. */
indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): IndexSignatureDeclaration | undefined;
/* @internal */ indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined, tracker?: SymbolTracker): IndexSignatureDeclaration | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): IndexSignatureDeclaration | undefined;
/* @internal */ indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined, tracker?: SymbolTracker): IndexSignatureDeclaration | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
/** Note that the resulting nodes cannot be checked. */
symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): EntityName | undefined;
/** Note that the resulting nodes cannot be checked. */
Expand All @@ -4132,6 +4133,7 @@ namespace ts {

getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
getSymbolAtLocation(node: Node): Symbol | undefined;
/* @internal */ getIndexInfosAtLocation(node: Node): readonly IndexInfo[] | undefined;
getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[];
/**
* The function returns the value (local variable) symbol of an identifier in the short-hand property assignment.
Expand Down Expand Up @@ -4244,7 +4246,7 @@ namespace ts {
/* @internal */ createPromiseType(type: Type): Type;

/* @internal */ isTypeAssignableTo(source: Type, target: Type): boolean;
/* @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): Type;
/* @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], indexInfos: IndexInfo[]): Type;
/* @internal */ createSignature(
declaration: SignatureDeclaration | undefined,
typeParameters: readonly TypeParameter[] | undefined,
Expand All @@ -4256,7 +4258,7 @@ namespace ts {
flags: SignatureFlags
): Signature;
/* @internal */ createSymbol(flags: SymbolFlags, name: __String): TransientSymbol;
/* @internal */ createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo;
/* @internal */ createIndexInfo(keyType: Type, type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo;
/* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult;
/* @internal */ tryFindAmbientModule(moduleName: string): Symbol | undefined;
/* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined;
Expand Down Expand Up @@ -5272,8 +5274,7 @@ namespace ts {
/* @internal */ properties?: Symbol[]; // Properties
/* @internal */ callSignatures?: readonly Signature[]; // Call signatures of type
/* @internal */ constructSignatures?: readonly Signature[]; // Construct signatures of type
/* @internal */ stringIndexInfo?: IndexInfo; // String indexing info
/* @internal */ numberIndexInfo?: IndexInfo; // Numeric indexing info
/* @internal */ indexInfos?: readonly IndexInfo[]; // Index signatures
/* @internal */ objectTypeWithoutAbstractConstructSignatures?: ObjectType;
}

Expand All @@ -5298,8 +5299,7 @@ namespace ts {
declaredProperties: Symbol[]; // Declared members
declaredCallSignatures: Signature[]; // Declared call signatures
declaredConstructSignatures: Signature[]; // Declared construct signatures
declaredStringIndexInfo?: IndexInfo; // Declared string indexing info
declaredNumberIndexInfo?: IndexInfo; // Declared numeric indexing info
declaredIndexInfos: IndexInfo[]; // Declared index signatures
}

/**
Expand Down Expand Up @@ -5457,6 +5457,7 @@ namespace ts {
properties: Symbol[]; // Properties
callSignatures: readonly Signature[]; // Call signatures of type
constructSignatures: readonly Signature[]; // Construct signatures of type
indexInfos: readonly IndexInfo[]; // Index signatures
}

/* @internal */
Expand Down Expand Up @@ -5693,6 +5694,7 @@ namespace ts {
}

export interface IndexInfo {
keyType: Type;
type: Type;
isReadonly: boolean;
declaration?: IndexSignatureDeclaration;
Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/convertToMappedObjectType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace ts.codefix {
const fixIdAddMissingTypeof = "fixConvertToMappedObjectType";
const fixId = fixIdAddMissingTypeof;
const errorCodes = [Diagnostics.An_index_signature_parameter_type_cannot_be_a_union_type_Consider_using_a_mapped_object_type_instead.code];
const errorCodes = [Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead.code];

type FixableDeclaration = InterfaceDeclaration | TypeAliasDeclaration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace ts.codefix {
function createMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind): void {
const indexInfoOfKind = checker.getIndexInfoOfType(type, kind);
if (indexInfoOfKind) {
insertInterfaceMemberNode(sourceFile, classDeclaration, checker.indexInfoToIndexSignatureDeclaration(indexInfoOfKind, kind, classDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context))!);
insertInterfaceMemberNode(sourceFile, classDeclaration, checker.indexInfoToIndexSignatureDeclaration(indexInfoOfKind, classDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context))!);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/services/codefixes/fixInvalidImportSyntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ namespace ts.codefix {
Diagnostics.Type_0_is_not_assignable_to_type_1.code,
Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated.code,
Diagnostics.Type_predicate_0_is_not_assignable_to_1.code,
Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2.code,
Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2.code,
Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1.code,
Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3.code,
Diagnostics._0_index_type_1_is_not_assignable_to_2_index_type_3.code,
Diagnostics.Property_0_in_type_1_is_not_assignable_to_the_same_property_in_base_type_2.code,
Diagnostics.Property_0_in_type_1_is_not_assignable_to_type_2.code,
Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property.code,
Expand Down
26 changes: 15 additions & 11 deletions src/services/codefixes/inferFromUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,13 +955,15 @@ namespace ts.codefix {
}
calls.push(...checker.getSignaturesOfType(anon, SignatureKind.Call));
constructs.push(...checker.getSignaturesOfType(anon, SignatureKind.Construct));
if (anon.stringIndexInfo) {
stringIndices.push(anon.stringIndexInfo.type);
stringIndexReadonly = stringIndexReadonly || anon.stringIndexInfo.isReadonly;
const stringIndexInfo = checker.getIndexInfoOfType(anon, IndexKind.String);
if (stringIndexInfo) {
stringIndices.push(stringIndexInfo.type);
stringIndexReadonly = stringIndexReadonly || stringIndexInfo.isReadonly;
}
if (anon.numberIndexInfo) {
numberIndices.push(anon.numberIndexInfo.type);
numberIndexReadonly = numberIndexReadonly || anon.numberIndexInfo.isReadonly;
const numberIndexInfo = checker.getIndexInfoOfType(anon, IndexKind.Number);
if (numberIndexInfo) {
numberIndices.push(numberIndexInfo.type);
numberIndexReadonly = numberIndexReadonly || numberIndexInfo.isReadonly;
}
}
const members = mapEntries(props, (name, types) => {
Expand All @@ -970,13 +972,15 @@ namespace ts.codefix {
s.type = checker.getUnionType(types);
return [name, s];
});
const indexInfos = [];
if (stringIndices.length) indexInfos.push(checker.createIndexInfo(checker.getStringType(), checker.getUnionType(stringIndices), stringIndexReadonly));
if (numberIndices.length) indexInfos.push(checker.createIndexInfo(checker.getNumberType(), checker.getUnionType(numberIndices), numberIndexReadonly));
return checker.createAnonymousType(
anons[0].symbol,
members as UnderscoreEscapedMap<TransientSymbol>,
calls,
constructs,
stringIndices.length ? checker.createIndexInfo(checker.getUnionType(stringIndices), stringIndexReadonly) : undefined,
numberIndices.length ? checker.createIndexInfo(checker.getUnionType(numberIndices), numberIndexReadonly) : undefined);
indexInfos);
}

function inferTypes(usage: Usage): Type[] {
Expand Down Expand Up @@ -1015,8 +1019,8 @@ namespace ts.codefix {
}
const callSignatures: Signature[] = usage.calls ? [getSignatureFromCalls(usage.calls)] : [];
const constructSignatures: Signature[] = usage.constructs ? [getSignatureFromCalls(usage.constructs)] : [];
const stringIndexInfo = usage.stringIndex && checker.createIndexInfo(combineFromUsage(usage.stringIndex), /*isReadonly*/ false);
return checker.createAnonymousType(/*symbol*/ undefined, members, callSignatures, constructSignatures, stringIndexInfo, /*numberIndexInfo*/ undefined);
const indexInfos = usage.stringIndex ? [checker.createIndexInfo(checker.getStringType(), combineFromUsage(usage.stringIndex), /*isReadonly*/ false)] : [];
return checker.createAnonymousType(/*symbol*/ undefined, members, callSignatures, constructSignatures, indexInfos);
}

function inferNamedTypesFromProperties(usage: Usage): Type[] {
Expand Down Expand Up @@ -1121,7 +1125,7 @@ namespace ts.codefix {
}

function getFunctionFromCalls(calls: CallUsage[]) {
return checker.createAnonymousType(/*symbol*/ undefined, createSymbolTable(), [getSignatureFromCalls(calls)], emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
return checker.createAnonymousType(/*symbol*/ undefined, createSymbolTable(), [getSignatureFromCalls(calls)], emptyArray, emptyArray);
}

function getSignatureFromCalls(calls: CallUsage[]): Signature {
Expand Down
5 changes: 2 additions & 3 deletions src/services/codefixes/returnValueCorrect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace ts.codefix {
const member = checker.createSymbol(SymbolFlags.Property, label.escapedText);
member.type = checker.getTypeAtLocation(expression);
const members = createSymbolTable([member]);
return checker.createAnonymousType(/*symbol*/ undefined, members, [], [], /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
return checker.createAnonymousType(/*symbol*/ undefined, members, [], [], []);
}

function getFixInfo(checker: TypeChecker, declaration: FunctionLikeDeclaration, expectType: Type, isFunctionType: boolean): Info | undefined {
Expand Down Expand Up @@ -152,8 +152,7 @@ namespace ts.codefix {
createSymbolTable(),
[newSig],
[],
/*stringIndexInfo*/ undefined,
/*numberIndexInfo*/ undefined);
[]);
}
else {
exprType = checker.getAnyType();
Expand Down
7 changes: 1 addition & 6 deletions src/services/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,7 @@ namespace ts.GoToDefinition {

// At 'x.foo', see if the type of 'x' has an index signature, and if so find its declarations.
function getDefinitionInfoForIndexSignatures(node: Node, checker: TypeChecker): DefinitionInfo[] | undefined {
if (!isPropertyAccessExpression(node.parent) || node.parent.name !== node) return;
const type = checker.getTypeAtLocation(node.parent.expression);
return mapDefined(type.isUnionOrIntersection() ? type.types : [type], nonUnionType => {
const info = checker.getIndexInfoOfType(nonUnionType, IndexKind.String);
return info && info.declaration && createDefinitionFromSignatureDeclaration(checker, info.declaration);
});
return mapDefined(checker.getIndexInfosAtLocation(node), info => info.declaration && createDefinitionFromSignatureDeclaration(checker, info.declaration));
}

function getSymbol(node: Node, checker: TypeChecker): Symbol | undefined {
Expand Down
Loading