Skip to content

Commit d1fde37

Browse files
author
Andy
authored
Symbol kind for a method on a mapped type should still be 'method' (#23478)
1 parent c645f17 commit d1fde37

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/services/symbolDisplay.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ namespace ts.SymbolDisplay {
2626
}
2727

2828
function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker: TypeChecker, symbol: Symbol, location: Node): ScriptElementKind {
29+
const roots = typeChecker.getRootSymbols(symbol);
30+
// If this is a method from a mapped type, leave as a method so long as it still has a call signature.
31+
if (roots.length === 1
32+
&& first(roots).flags & SymbolFlags.Method
33+
// Ensure the mapped version is still a method, as opposed to `{ [K in keyof I]: number }`.
34+
&& typeChecker.getTypeOfSymbolAtLocation(symbol, location).getNonNullableType().getCallSignatures().length !== 0) {
35+
return ScriptElementKind.memberFunctionElement;
36+
}
37+
2938
if (typeChecker.isUndefinedSymbol(symbol)) {
3039
return ScriptElementKind.variableElement;
3140
}

tests/cases/fourslash/server/quickInfoMappedSpreadTypes.ts renamed to tests/cases/fourslash/quickInfoMappedSpreadTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../fourslash.ts"/>
1+
/// <reference path="./fourslash.ts"/>
22

33
////interface Foo {
44
//// /** Doc */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="./fourslash.ts"/>
2+
3+
////interface I { m(): void; }
4+
////declare const o: { [K in keyof I]: number };
5+
////o.m/*0*/;
6+
////
7+
////declare const p: { [K in keyof I]: I[K] };
8+
////p.m/*1*/;
9+
10+
verify.quickInfoAt("0", "(property) m: number");
11+
verify.quickInfoAt("1", "(method) m(): void");

0 commit comments

Comments
 (0)