Skip to content

Commit 97b3d7a

Browse files
author
Arthur Ozga
committed
make index signature fix work with generics
1 parent 2f51b36 commit 97b3d7a

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace ts {
7979
getDeclaredTypeOfSymbol,
8080
getPropertiesOfType,
8181
getPropertyOfType,
82+
getIndexInfoOfType,
8283
getSignaturesOfType,
8384
getIndexTypeOfType,
8485
getBaseTypes,

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,7 @@ namespace ts {
23352335
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
23362336
getPropertiesOfType(type: Type): Symbol[];
23372337
getPropertyOfType(type: Type, propertyName: string): Symbol;
2338+
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo;
23382339
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
23392340
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
23402341
getBaseTypes(type: InterfaceType): ObjectType[];

src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ namespace ts.codefix {
3131
let insertion = "";
3232

3333
if (!hasNumericIndexSignature) {
34-
const typeNumericIndexInfo = implementedType.declaredNumberIndexInfo;
34+
const typeNumericIndexInfo = checker.getIndexInfoOfType(implementedType, IndexKind.Number);
3535
if (typeNumericIndexInfo) {
3636
insertion = checker.indexSignatureToString(typeNumericIndexInfo, SyntaxKind.NumberKeyword, classDecl);
3737
}
3838
}
3939

4040
if (!hasStringIndexSignature) {
41-
const typeStringIndexInfo = implementedType.declaredStringIndexInfo;
41+
const typeStringIndexInfo = checker.getIndexInfoOfType(implementedType, IndexKind.String);
4242
if (typeStringIndexInfo) {
4343
insertion += checker.indexSignatureToString(typeStringIndexInfo, SyntaxKind.StringKeyword, classDecl);
4444
}

tests/cases/fourslash/codeFixUnImplementedInterfaceIndexSignaturesString.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/// <reference path='fourslash.ts' />
22

3-
//// interface I {
4-
//// [x: string]: number;
3+
//// interface I<X> {
4+
//// [x: string]: X;
55
//// }
66
////
7-
//// class C implements I {[| |]}
7+
//// class C implements I<number> {[| |]}
88

99
verify.rangeAfterCodeFix(`
1010
[x: string]: number;

0 commit comments

Comments
 (0)