diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e2c6e4d6a53..f75ba15254b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -79,6 +79,7 @@ namespace ts { getDeclaredTypeOfSymbol, getPropertiesOfType, getPropertyOfType, + getIndexInfoOfType, getSignaturesOfType, getIndexTypeOfType, getBaseTypes, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index eb9584f638a..81b4005ae5e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2335,6 +2335,7 @@ namespace ts { getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol; + getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo; getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; getIndexTypeOfType(type: Type, kind: IndexKind): Type; getBaseTypes(type: InterfaceType): ObjectType[]; diff --git a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts index e82c579a54f..11db00eb43c 100644 --- a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts +++ b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts @@ -31,14 +31,14 @@ namespace ts.codefix { let insertion = ""; if (!hasNumericIndexSignature) { - const typeNumericIndexInfo = implementedType.declaredNumberIndexInfo; + const typeNumericIndexInfo = checker.getIndexInfoOfType(implementedType, IndexKind.Number); if (typeNumericIndexInfo) { insertion = checker.indexSignatureToString(typeNumericIndexInfo, SyntaxKind.NumberKeyword, classDecl); } } if (!hasStringIndexSignature) { - const typeStringIndexInfo = implementedType.declaredStringIndexInfo; + const typeStringIndexInfo = checker.getIndexInfoOfType(implementedType, IndexKind.String); if (typeStringIndexInfo) { insertion += checker.indexSignatureToString(typeStringIndexInfo, SyntaxKind.StringKeyword, classDecl); } diff --git a/tests/cases/fourslash/codeFixUnImplementedInterfaceIndexSignaturesString.ts b/tests/cases/fourslash/codeFixUnImplementedInterfaceIndexSignaturesString.ts index 37abd751382..4b595c6eda7 100644 --- a/tests/cases/fourslash/codeFixUnImplementedInterfaceIndexSignaturesString.ts +++ b/tests/cases/fourslash/codeFixUnImplementedInterfaceIndexSignaturesString.ts @@ -1,10 +1,10 @@ /// -//// interface I { -//// [x: string]: number; +//// interface I { +//// [x: string]: X; //// } //// -//// class C implements I {[| |]} +//// class C implements I {[| |]} verify.rangeAfterCodeFix(` [x: string]: number;