mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 19:07:27 -06:00
make index signature fix work with generics
This commit is contained in:
parent
2f51b363bf
commit
97b3d7a9ef
@ -79,6 +79,7 @@ namespace ts {
|
||||
getDeclaredTypeOfSymbol,
|
||||
getPropertiesOfType,
|
||||
getPropertyOfType,
|
||||
getIndexInfoOfType,
|
||||
getSignaturesOfType,
|
||||
getIndexTypeOfType,
|
||||
getBaseTypes,
|
||||
|
||||
@ -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[];
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user