Skip to content

Commit 794f3a5

Browse files
author
Andy
authored
goToTypeDefinition: Go to function return type (#25952)
* goToTypeDefinition: Go to function return type * Add more tests * If a function returns 'void' or some other type with no definition, just return the function definition.
1 parent eaf0d59 commit 794f3a5

8 files changed

+105
-37
lines changed

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ Actual: ${stringify(fullActual)}`);
16741674
for (const { name, text } of outputFiles) {
16751675
const fromTestFile = this.getFileContent(name);
16761676
if (fromTestFile !== text) {
1677-
this.raiseError("Emit output is not as expected: " + showTextDiff(fromTestFile, text));
1677+
this.raiseError(`Emit output for ${name} is not as expected: ${showTextDiff(fromTestFile, text)}`);
16781678
}
16791679
}
16801680
}

src/services/goToDefinition.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,30 @@ namespace ts.GoToDefinition {
136136
}
137137

138138
const symbol = typeChecker.getSymbolAtLocation(node);
139-
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, node);
140-
return type && flatMap(type.isUnion() && !(type.flags & TypeFlags.Enum) ? type.types : [type], t =>
141-
t.symbol && getDefinitionFromSymbol(typeChecker, t.symbol, node));
139+
if (!symbol) return undefined;
140+
141+
const typeAtLocation = typeChecker.getTypeOfSymbolAtLocation(symbol, node);
142+
const returnType = tryGetReturnTypeOfFunction(symbol, typeAtLocation, typeChecker);
143+
const fromReturnType = returnType && definitionFromType(returnType, typeChecker, node);
144+
// If a function returns 'void' or some other type with no definition, just return the function definition.
145+
return fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
146+
}
147+
148+
function definitionFromType(type: Type, checker: TypeChecker, node: Node): DefinitionInfo[] {
149+
return flatMap(type.isUnion() && !(type.flags & TypeFlags.Enum) ? type.types : [type], t =>
150+
t.symbol && getDefinitionFromSymbol(checker, t.symbol, node));
151+
}
152+
153+
function tryGetReturnTypeOfFunction(symbol: Symbol, type: Type, checker: TypeChecker): Type | undefined {
154+
// If the type is just a function's inferred type,
155+
// go-to-type should go to the return type instead, since go-to-definition takes you to the function anyway.
156+
if (type.symbol === symbol ||
157+
// At `const f = () => {}`, the symbol is `f` and the type symbol is at `() => {}`
158+
symbol.valueDeclaration && type.symbol && isVariableDeclaration(symbol.valueDeclaration) && symbol.valueDeclaration.initializer === type.symbol.valueDeclaration as Node) {
159+
const sigs = type.getCallSignatures();
160+
if (sigs.length === 1) return checker.getReturnTypeOfSignature(first(sigs));
161+
}
162+
return undefined;
142163
}
143164

144165
export function getDefinitionAndBoundSpan(program: Program, sourceFile: SourceFile, position: number): DefinitionInfoAndBoundSpan | undefined {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////interface /*I*/I { x: number; }
4+
////interface /*J*/J { y: number; }
5+
////
6+
////function f0(): I { return { x: 0 }; }
7+
////
8+
////type T = /*T*/(i: I) => I;
9+
////const f1: T = i => ({ x: i.x + 1 });
10+
////
11+
////const f2 = (i: I): I => ({ x: i.x + 1 });
12+
////
13+
////const f3 = (i: I) => (/*f3Def*/{ x: i.x + 1 });
14+
////
15+
////const f4 = (i: I) => i;
16+
////
17+
////const f5 = /*f5Def*/(i: I): I | J => ({ x: i.x + 1 });
18+
////
19+
////const f6 = (i: I, j: J, b: boolean) => b ? i : j;
20+
////
21+
////const f7 = /*f7Def*/(i: I) => {};
22+
////
23+
////function f8(i: I): I;
24+
////function f8(j: J): J;
25+
////function /*f8Def*/f8(ij: any): any { return ij; }
26+
////
27+
/////*f0*/f0();
28+
/////*f1*/f1();
29+
/////*f2*/f2();
30+
/////*f3*/f3();
31+
/////*f4*/f4();
32+
/////*f5*/f5();
33+
/////*f6*/f6();
34+
/////*f7*/f7();
35+
/////*f8*/f8();
36+
37+
verify.goToType({
38+
f0: "I",
39+
f1: "T",
40+
f2: "I",
41+
f3: "f3Def",
42+
f4: "I",
43+
f5: ["I", "J"],
44+
f6: ["I", "J"],
45+
f7: "f7Def",
46+
f8: "f8Def",
47+
});

tests/cases/fourslash/server/declarationMapsEnableMapping_NoInline.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// @emitThisFile: true
1717
////export class Foo {
1818
//// member: string;
19-
//// /*2*/methodName(propName: SomeType): void {}
19+
//// /*2*/methodName(propName: SomeType): SomeType { return propName; }
2020
//// otherMethod() {
2121
//// if (Math.random() > 0.5) {
2222
//// return {x: 42};
@@ -25,7 +25,7 @@
2525
//// }
2626
////}
2727
////
28-
////export interface SomeType {
28+
////export interface /*SomeType*/SomeType {
2929
//// member: number;
3030
////}
3131

@@ -40,7 +40,7 @@
4040
////var Foo = /** @class */ (function () {
4141
//// function Foo() {
4242
//// }
43-
//// Foo.prototype.methodName = function (propName) { };
43+
//// Foo.prototype.methodName = function (propName) { return propName; };
4444
//// Foo.prototype.otherMethod = function () {
4545
//// if (Math.random() > 0.5) {
4646
//// return { x: 42 };
@@ -50,15 +50,15 @@
5050
//// return Foo;
5151
////}());
5252
////exports.Foo = Foo;
53-
//////# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBO0lBQUE7SUFTQSxDQUFDO0lBUEcsd0JBQVUsR0FBVixVQUFXLFFBQWtCLElBQVMsQ0FBQztJQUN2Qyx5QkFBVyxHQUFYO1FBQ0ksSUFBSSxJQUFJLENBQUMsTUFBTSxFQUFFLEdBQUcsR0FBRyxFQUFFO1lBQ3JCLE9BQU8sRUFBQyxDQUFDLEVBQUUsRUFBRSxFQUFDLENBQUM7U0FDbEI7UUFDRCxPQUFPLEVBQUMsQ0FBQyxFQUFFLEtBQUssRUFBQyxDQUFDO0lBQ3RCLENBQUM7SUFDTCxVQUFDO0FBQUQsQ0FBQyxBQVRELElBU0M7QUFUWSxrQkFBRyJ9
53+
//////# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBO0lBQUE7SUFTQSxDQUFDO0lBUEcsd0JBQVUsR0FBVixVQUFXLFFBQWtCLElBQWMsT0FBTyxRQUFRLENBQUMsQ0FBQyxDQUFDO0lBQzdELHlCQUFXLEdBQVg7UUFDSSxJQUFJLElBQUksQ0FBQyxNQUFNLEVBQUUsR0FBRyxHQUFHLEVBQUU7WUFDckIsT0FBTyxFQUFDLENBQUMsRUFBRSxFQUFFLEVBQUMsQ0FBQztTQUNsQjtRQUNELE9BQU8sRUFBQyxDQUFDLEVBQUUsS0FBSyxFQUFDLENBQUM7SUFDdEIsQ0FBQztJQUNMLFVBQUM7QUFBRCxDQUFDLEFBVEQsSUFTQztBQVRZLGtCQUFHIn0=
5454

5555
// @Filename: /dist/index.d.ts.map
56-
////{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
56+
////{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IACxC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
5757

5858
// @Filename: /dist/index.d.ts
5959
////export declare class Foo {
6060
//// member: string;
61-
//// methodName(propName: SomeType): void;
61+
//// methodName(propName: SomeType): SomeType;
6262
//// otherMethod(): {
6363
//// x: number;
6464
//// y?: undefined;
@@ -76,7 +76,7 @@ goTo.file("/index.ts");
7676
verify.getEmitOutput(["/dist/index.js", "/dist/index.d.ts.map", "/dist/index.d.ts"]);
7777

7878
verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan
79-
verify.goToType("1", "2"); // getTypeDefinitionAtPosition
79+
verify.goToType("1", "SomeType"); // getTypeDefinitionAtPosition
8080
goTo.marker("1");
8181
verify.goToDefinitionIs("2"); // getDefinitionAtPosition
8282
goTo.implementation(); // getImplementationAtPosition

tests/cases/fourslash/server/declarationMapsEnableMapping_NoInlineSources.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// @emitThisFile: true
1818
////export class Foo {
1919
//// member: string;
20-
//// /*2*/methodName(propName: SomeType): void {}
20+
//// /*2*/methodName(propName: SomeType): SomeType { return propName; }
2121
//// otherMethod() {
2222
//// if (Math.random() > 0.5) {
2323
//// return {x: 42};
@@ -26,7 +26,7 @@
2626
//// }
2727
////}
2828
////
29-
////export interface SomeType {
29+
////export interface /*SomeType*/SomeType {
3030
//// member: number;
3131
////}
3232

@@ -41,7 +41,7 @@
4141
////var Foo = /** @class */ (function () {
4242
//// function Foo() {
4343
//// }
44-
//// Foo.prototype.methodName = function (propName) { };
44+
//// Foo.prototype.methodName = function (propName) { return propName; };
4545
//// Foo.prototype.otherMethod = function () {
4646
//// if (Math.random() > 0.5) {
4747
//// return { x: 42 };
@@ -51,15 +51,15 @@
5151
//// return Foo;
5252
////}());
5353
////exports.Foo = Foo;
54-
//////# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBO0lBQUE7SUFTQSxDQUFDO0lBUEcsd0JBQVUsR0FBVixVQUFXLFFBQWtCLElBQVMsQ0FBQztJQUN2Qyx5QkFBVyxHQUFYO1FBQ0ksSUFBSSxJQUFJLENBQUMsTUFBTSxFQUFFLEdBQUcsR0FBRyxFQUFFO1lBQ3JCLE9BQU8sRUFBQyxDQUFDLEVBQUUsRUFBRSxFQUFDLENBQUM7U0FDbEI7UUFDRCxPQUFPLEVBQUMsQ0FBQyxFQUFFLEtBQUssRUFBQyxDQUFDO0lBQ3RCLENBQUM7SUFDTCxVQUFDO0FBQUQsQ0FBQyxBQVRELElBU0M7QUFUWSxrQkFBRyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBjbGFzcyBGb28ge1xuICAgIG1lbWJlcjogc3RyaW5nO1xuICAgIG1ldGhvZE5hbWUocHJvcE5hbWU6IFNvbWVUeXBlKTogdm9pZCB7fVxuICAgIG90aGVyTWV0aG9kKCkge1xuICAgICAgICBpZiAoTWF0aC5yYW5kb20oKSA+IDAuNSkge1xuICAgICAgICAgICAgcmV0dXJuIHt4OiA0Mn07XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHt5OiBcInllc1wifTtcbiAgICB9XG59XG5cbmV4cG9ydCBpbnRlcmZhY2UgU29tZVR5cGUge1xuICAgIG1lbWJlcjogbnVtYmVyO1xufSJdfQ==
54+
//////# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBO0lBQUE7SUFTQSxDQUFDO0lBUEcsd0JBQVUsR0FBVixVQUFXLFFBQWtCLElBQWMsT0FBTyxRQUFRLENBQUMsQ0FBQyxDQUFDO0lBQzdELHlCQUFXLEdBQVg7UUFDSSxJQUFJLElBQUksQ0FBQyxNQUFNLEVBQUUsR0FBRyxHQUFHLEVBQUU7WUFDckIsT0FBTyxFQUFDLENBQUMsRUFBRSxFQUFFLEVBQUMsQ0FBQztTQUNsQjtRQUNELE9BQU8sRUFBQyxDQUFDLEVBQUUsS0FBSyxFQUFDLENBQUM7SUFDdEIsQ0FBQztJQUNMLFVBQUM7QUFBRCxDQUFDLEFBVEQsSUFTQztBQVRZLGtCQUFHIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGNsYXNzIEZvbyB7XG4gICAgbWVtYmVyOiBzdHJpbmc7XG4gICAgbWV0aG9kTmFtZShwcm9wTmFtZTogU29tZVR5cGUpOiBTb21lVHlwZSB7IHJldHVybiBwcm9wTmFtZTsgfVxuICAgIG90aGVyTWV0aG9kKCkge1xuICAgICAgICBpZiAoTWF0aC5yYW5kb20oKSA+IDAuNSkge1xuICAgICAgICAgICAgcmV0dXJuIHt4OiA0Mn07XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHt5OiBcInllc1wifTtcbiAgICB9XG59XG5cbmV4cG9ydCBpbnRlcmZhY2UgU29tZVR5cGUge1xuICAgIG1lbWJlcjogbnVtYmVyO1xufSJdfQ==
5555

5656
// @Filename: /dist/index.d.ts.map
57-
////{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
57+
////{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IACxC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
5858

5959
// @Filename: /dist/index.d.ts
6060
////export declare class Foo {
6161
//// member: string;
62-
//// methodName(propName: SomeType): void;
62+
//// methodName(propName: SomeType): SomeType;
6363
//// otherMethod(): {
6464
//// x: number;
6565
//// y?: undefined;
@@ -77,7 +77,7 @@ goTo.file("/index.ts");
7777
verify.getEmitOutput(["/dist/index.js", "/dist/index.d.ts.map", "/dist/index.d.ts"]);
7878

7979
verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan
80-
verify.goToType("1", "2"); // getTypeDefinitionAtPosition
80+
verify.goToType("1", "SomeType"); // getTypeDefinitionAtPosition
8181
goTo.marker("1");
8282
verify.goToDefinitionIs("2"); // getDefinitionAtPosition
8383
goTo.implementation(); // getImplementationAtPosition

tests/cases/fourslash/server/declarationMapsGeneratedMapsEnableMapping.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// @emitThisFile: true
1616
////export class Foo {
1717
//// member: string;
18-
//// /*2*/methodName(propName: SomeType): void {}
18+
//// /*2*/methodName(propName: SomeType): SomeType { return propName; }
1919
//// otherMethod() {
2020
//// if (Math.random() > 0.5) {
2121
//// return {x: 42};
@@ -24,7 +24,7 @@
2424
//// }
2525
////}
2626
////
27-
////export interface SomeType {
27+
////export interface /*SomeType*/SomeType {
2828
//// member: number;
2929
////}
3030

@@ -39,7 +39,7 @@
3939
////var Foo = /** @class */ (function () {
4040
//// function Foo() {
4141
//// }
42-
//// Foo.prototype.methodName = function (propName) { };
42+
//// Foo.prototype.methodName = function (propName) { return propName; };
4343
//// Foo.prototype.otherMethod = function () {
4444
//// if (Math.random() > 0.5) {
4545
//// return { x: 42 };
@@ -52,12 +52,12 @@
5252
////
5353

5454
// @Filename: /dist/index.d.ts.map
55-
////{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
55+
////{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IACxC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
5656

5757
// @Filename: /dist/index.d.ts
5858
////export declare class Foo {
5959
//// member: string;
60-
//// methodName(propName: SomeType): void;
60+
//// methodName(propName: SomeType): SomeType;
6161
//// otherMethod(): {
6262
//// x: number;
6363
//// y?: undefined;
@@ -75,7 +75,7 @@ goTo.file("/index.ts");
7575
verify.getEmitOutput(["/dist/index.js", "/dist/index.d.ts.map", "/dist/index.d.ts"]);
7676

7777
verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan
78-
verify.goToType("1", "2"); // getTypeDefinitionAtPosition
78+
verify.goToType("1", "SomeType"); // getTypeDefinitionAtPosition
7979
goTo.marker("1");
8080
verify.goToDefinitionIs("2"); // getDefinitionAtPosition
8181
goTo.implementation(); // getImplementationAtPosition

tests/cases/fourslash/server/declarationMapsGeneratedMapsEnableMapping2.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// @emitThisFile: true
1818
////export class Foo {
1919
//// member: string;
20-
//// /*2*/methodName(propName: SomeType): void {}
20+
//// /*2*/methodName(propName: SomeType): SomeType { return propName; }
2121
//// otherMethod() {
2222
//// if (Math.random() > 0.5) {
2323
//// return {x: 42};
@@ -26,7 +26,7 @@
2626
//// }
2727
////}
2828
////
29-
////export interface SomeType {
29+
////export interface /*SomeType*/SomeType {
3030
//// member: number;
3131
////}
3232

@@ -36,15 +36,15 @@
3636
////instance.[|/*1*/methodName|]({member: 12});
3737

3838
// @Filename: /dist/index.js.map
39-
////{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;AAAA;IAAA;IASA,CAAC;IAPG,wBAAU,GAAV,UAAW,QAAkB,IAAS,CAAC;IACvC,yBAAW,GAAX;QACI,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE;YACrB,OAAO,EAAC,CAAC,EAAE,EAAE,EAAC,CAAC;SAClB;QACD,OAAO,EAAC,CAAC,EAAE,KAAK,EAAC,CAAC;IACtB,CAAC;IACL,UAAC;AAAD,CAAC,AATD,IASC;AATY,kBAAG"}
39+
////{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;AAAA;IAAA;IASA,CAAC;IAPG,wBAAU,GAAV,UAAW,QAAkB,IAAc,OAAO,QAAQ,CAAC,CAAC,CAAC;IAC7D,yBAAW,GAAX;QACI,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE;YACrB,OAAO,EAAC,CAAC,EAAE,EAAE,EAAC,CAAC;SAClB;QACD,OAAO,EAAC,CAAC,EAAE,KAAK,EAAC,CAAC;IACtB,CAAC;IACL,UAAC;AAAD,CAAC,AATD,IASC;AATY,kBAAG"}
4040

4141
// @Filename: /dist/index.js
4242
////"use strict";
4343
////exports.__esModule = true;
4444
////var Foo = /** @class */ (function () {
4545
//// function Foo() {
4646
//// }
47-
//// Foo.prototype.methodName = function (propName) { };
47+
//// Foo.prototype.methodName = function (propName) { return propName; };
4848
//// Foo.prototype.otherMethod = function () {
4949
//// if (Math.random() > 0.5) {
5050
//// return { x: 42 };
@@ -57,12 +57,12 @@
5757
//////# sourceMappingURL=index.js.map
5858

5959
// @Filename: /dist/index.d.ts.map
60-
////{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
60+
////{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IACxC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
6161

6262
// @Filename: /dist/index.d.ts
6363
////export declare class Foo {
6464
//// member: string;
65-
//// methodName(propName: SomeType): void;
65+
//// methodName(propName: SomeType): SomeType;
6666
//// otherMethod(): {
6767
//// x: number;
6868
//// y?: undefined;
@@ -80,7 +80,7 @@ goTo.file("/index.ts");
8080
verify.getEmitOutput(["/dist/index.js.map", "/dist/index.js", "/dist/index.d.ts.map", "/dist/index.d.ts"]);
8181

8282
verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan
83-
verify.goToType("1", "2"); // getTypeDefinitionAtPosition
83+
verify.goToType("1", "SomeType"); // getTypeDefinitionAtPosition
8484
goTo.marker("1");
8585
verify.goToDefinitionIs("2"); // getDefinitionAtPosition
8686
goTo.implementation(); // getImplementationAtPosition

tests/cases/fourslash/server/declarationMapsGeneratedMapsEnableMapping3.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// @emitThisFile: true
1717
////export class Foo {
1818
//// member: string;
19-
//// /*2*/methodName(propName: SomeType): void {}
19+
//// /*2*/methodName(propName: SomeType): SomeType { return propName; }
2020
//// otherMethod() {
2121
//// if (Math.random() > 0.5) {
2222
//// return {x: 42};
@@ -25,7 +25,7 @@
2525
//// }
2626
////}
2727
////
28-
////export interface SomeType {
28+
////export interface /*SomeType*/SomeType {
2929
//// member: number;
3030
////}
3131

@@ -40,7 +40,7 @@
4040
////var Foo = /** @class */ (function () {
4141
//// function Foo() {
4242
//// }
43-
//// Foo.prototype.methodName = function (propName) { };
43+
//// Foo.prototype.methodName = function (propName) { return propName; };
4444
//// Foo.prototype.otherMethod = function () {
4545
//// if (Math.random() > 0.5) {
4646
//// return { x: 42 };
@@ -53,12 +53,12 @@
5353
////
5454

5555
// @Filename: /dist/index.d.ts.map
56-
////{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
56+
////{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IACxC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}
5757

5858
// @Filename: /dist/index.d.ts
5959
////export declare class Foo {
6060
//// member: string;
61-
//// methodName(propName: SomeType): void;
61+
//// methodName(propName: SomeType): SomeType;
6262
//// otherMethod(): {
6363
//// x: number;
6464
//// y?: undefined;
@@ -76,7 +76,7 @@ goTo.file("/index.ts");
7676
verify.getEmitOutput(["/dist/index.js", "/dist/index.d.ts.map", "/dist/index.d.ts"]);
7777

7878
verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan
79-
verify.goToType("1", "2"); // getTypeDefinitionAtPosition
79+
verify.goToType("1", "SomeType"); // getTypeDefinitionAtPosition
8080
goTo.marker("1");
8181
verify.goToDefinitionIs("2"); // getDefinitionAtPosition
8282
goTo.implementation(); // getImplementationAtPosition

0 commit comments

Comments
 (0)