Skip to content

Commit a8230d3

Browse files
author
Andy Hanson
committed
goToTypeDefinition: Go to function return type
1 parent f12e9a8 commit a8230d3

8 files changed

+70
-35
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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,26 @@ namespace ts.GoToDefinition {
135135
}
136136

137137
const symbol = typeChecker.getSymbolAtLocation(node);
138-
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, node);
138+
const type = symbol && getTypeForTypeDefinition(symbol, node, typeChecker);
139139
return type && flatMap(type.isUnion() && !(type.flags & TypeFlags.Enum) ? type.types : [type], t =>
140140
t.symbol && getDefinitionFromSymbol(typeChecker, t.symbol, node));
141141
}
142142

143+
function getTypeForTypeDefinition(symbol: Symbol, node: Node, checker: TypeChecker): Type | undefined {
144+
const type = checker.getTypeOfSymbolAtLocation(symbol, node);
145+
if (!type) return undefined;
146+
147+
// If the type is just a function's inferred type,
148+
// go-to-type should go to the return type instead, since go-to-definition takes you to the function anyway.
149+
if (type.symbol === symbol ||
150+
// At `const f = () => {}`, the symbol is `f` and the type symbol is at `() => {}`
151+
symbol.valueDeclaration && type.symbol && isVariableDeclaration(symbol.valueDeclaration) && symbol.valueDeclaration.initializer === type.symbol.valueDeclaration as Node) {
152+
const sigs = type.getCallSignatures();
153+
if (sigs.length === 1) return checker.getReturnTypeOfSignature(first(sigs));
154+
}
155+
return type;
156+
}
157+
143158
export function getDefinitionAndBoundSpan(program: Program, sourceFile: SourceFile, position: number): DefinitionInfoAndBoundSpan | undefined {
144159
const definitions = getDefinitionAtPosition(program, sourceFile, position);
145160

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////interface /*I*/I { x: number; }
4+
////
5+
////function f0(): I { return { x: 0 }; }
6+
////
7+
////type T = /*T*/(i: I) => I;
8+
////const f1: T = i => ({ x: i.x + 1 });
9+
////
10+
////const f2 = (i: I): I => ({ x: i.x + 1 });
11+
////
12+
/////*f0*/f0();
13+
/////*f1*/f1();
14+
/////*f2*/f2();
15+
16+
verify.goToType({
17+
f0: "I",
18+
f1: "T",
19+
f2: "I",
20+
});

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)