Skip to content

Go-to-type is not useful for function #25933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jul 25, 2018 · 2 comments
Closed

Go-to-type is not useful for function #25933

ghost opened this issue Jul 25, 2018 · 2 comments
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@ghost
Copy link

ghost commented Jul 25, 2018

TypeScript Version: 3.1.0-dev.20180725

Search Terms:

Code

interface I { x: number; }
function f(): I { return { x: 0 }; }

f();

Go-to-type on f().

Expected behavior:

Takes me to I.

Actual behavior:

Takes me to f -- same as go-to-definition.

Contrast with this Kotlin code:

class C(val x: Int)

fun f() = C(0)

fun main() {
    f()
}

where go-to-declaration on f() takes me to the definition, but go-to-type takes me to C.

@ghost ghost added the Suggestion An idea for TypeScript label Jul 25, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jul 25, 2018

With this proposal function expressions and arrow functions that have a contextual type will have ambiguous behavior, should they go to the contextual type or the return type.

@ghost
Copy link
Author

ghost commented Jul 25, 2018

Presume you're talking about the following case -- then I think we should go to T and not I. (Since one can easily get to I from T but not the other way around.)

interface I { x: number; }
type T = (i: I) => I;
const f: T = i => ({ x: i.x + 1 });
f({ x: 0 });

@mhegazy mhegazy assigned ghost Jul 25, 2018
@mhegazy mhegazy added this to the TypeScript 3.1 milestone Jul 25, 2018
@ghost ghost added the Fixed A PR has been merged for this issue label Jul 26, 2018
@ghost ghost closed this as completed in #25952 Aug 7, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant