Skip to content

Commit 7f4aeee

Browse files
committed
only determine declaration is not class
1 parent 654ab5c commit 7f4aeee

7 files changed

+18
-23
lines changed

src/services/codefixes/convertToMappedObjectType.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,13 @@ namespace ts.codefix {
3535
})
3636
});
3737

38-
function isFixableDeclaration(node: Node): node is FixableDeclaration {
39-
return isInterfaceDeclaration(node) || (node.parent && isTypeLiteralNode(node) && isTypeAliasDeclaration(node.parent));
40-
}
41-
42-
function isIndexSignatureParameterName(node: Node): node is Identifier {
43-
return node && node.parent && node.parent.parent && node.parent.parent.parent &&
44-
isIdentifier(node) && isParameter(node.parent) && isIndexSignatureDeclaration(node.parent.parent) && isFixableDeclaration(node.parent.parent.parent);
38+
function isFixableParameterName(node: Node): boolean {
39+
return node && node.parent && node.parent.parent && node.parent.parent.parent && !isClassDeclaration(node.parent.parent.parent);
4540
}
4641

4742
function getFixableSignatureAtPosition(sourceFile: SourceFile, pos: number): Info | undefined {
4843
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
49-
if (!isIndexSignatureParameterName(token)) return undefined;
44+
if (!isFixableParameterName(token)) return undefined;
5045

5146
const indexSignature = <IndexSignatureDeclaration>token.parent.parent;
5247
const container = isInterfaceDeclaration(indexSignature.parent) ? indexSignature.parent : <TypeAliasDeclaration>indexSignature.parent.parent;
@@ -59,7 +54,7 @@ namespace ts.codefix {
5954
container,
6055
otherMembers,
6156
parameterName: <Identifier>parameter.name,
62-
parameterType: parameter.type
57+
parameterType: parameter.type!
6358
};
6459
}
6560

tests/cases/fourslash/codeFixConvertToMappedObjectType1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ verify.codeFix({
1212
type SomeType = {
1313
[prop in K]: any;
1414
} & {
15-
a: string;
16-
};`
15+
a: string;
16+
};`
1717
})

tests/cases/fourslash/codeFixConvertToMappedObjectType10.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface Bar<T> { bar: T; }
1717
type SomeType<T> = Foo & Bar<T> & {
1818
[prop in K]: any;
1919
} & {
20-
a: number;
21-
b: T;
22-
};`
20+
a: number;
21+
b: T;
22+
};`
2323
})

tests/cases/fourslash/codeFixConvertToMappedObjectType11.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface Bar<T> { bar: T; }
1717
type SomeType<T> = Foo & Bar<T> & {
1818
readonly [prop in K]: any;
1919
} & {
20-
a: number;
21-
b: T;
22-
};`
20+
a: number;
21+
b: T;
22+
};`
2323
})

tests/cases/fourslash/codeFixConvertToMappedObjectType2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ verify.codeFix({
1212
type SomeType = {
1313
[prop in K]: any;
1414
} & {
15-
a: string;
16-
};`
15+
a: string;
16+
};`
1717
})

tests/cases/fourslash/codeFixConvertToMappedObjectType8.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ interface Bar { }
1616
type SomeType = Foo & Bar & {
1717
[prop in K]: any;
1818
} & {
19-
a: number;
20-
};`
19+
a: number;
20+
};`
2121
})

tests/cases/fourslash/codeFixConvertToMappedObjectType9.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ interface Bar<T> { bar: T; }
1616
type SomeType = Foo & Bar<number> & {
1717
[prop in K]: any;
1818
} & {
19-
a: number;
20-
};`
19+
a: number;
20+
};`
2121
})

0 commit comments

Comments
 (0)