make index signature fix work with generics

This commit is contained in:
Arthur Ozga 2016-12-08 17:19:19 -08:00
parent 2f51b363bf
commit 97b3d7a9ef
4 changed files with 7 additions and 5 deletions

View File

@ -79,6 +79,7 @@ namespace ts {
getDeclaredTypeOfSymbol,
getPropertiesOfType,
getPropertyOfType,
getIndexInfoOfType,
getSignaturesOfType,
getIndexTypeOfType,
getBaseTypes,

View File

@ -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[];

View File

@ -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);
}

View File

@ -1,10 +1,10 @@
/// <reference path='fourslash.ts' />
//// interface I {
//// [x: string]: number;
//// interface I<X> {
//// [x: string]: X;
//// }
////
//// class C implements I {[| |]}
//// class C implements I<number> {[| |]}
verify.rangeAfterCodeFix(`
[x: string]: number;