Skip to content
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

Go-to-definition should only show relevant definitions when value & type have same name #57959

Open
ulugbekna opened this issue Mar 27, 2024 · 6 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@ulugbekna
Copy link

πŸ”Ž Search Terms

"go to definition", "same identifier", "value", "type"

πŸ•— Version & Regression Information

Always was the case, AFAIK

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBMULxQN4F8oFgBQmDGB7AdgM6ywIrpYYBmArvtsAJYFRUAUAhgE4DmAXDACUSKKgD0YqD1yN8PGLigATCFVmMmLFgANg2qAAsIXCIGgCKYwBuEQstXrNRKLipQARrmAGoAWhjhoDnwlKEsOABsaaF1tABooCGt8GANcGh5vMMjovShsIPxPd2gaQggQ2RTGWzBwjmwIAWBCbF8Eri5cLigAFQBlACYAdgAWAE4BAHJgSagTKmNbYEUOUIio+LcaWGri2XlS8qgOW1XQSENjCAA6KAARRhCQNKgAWwggqGmAlxhJgH5MJggA

πŸ’» Code

type t = {} 

const t = {} 

function f(arg: t) { } // going to definition on `t` here​ gives definitions of both - type and value `t`, even though value `t` cannot be used in this place: tsc - error TS2749: 't' refers to a value, but is being used as a type here. Did you mean 'typeof t'?

πŸ™ Actual behavior

"Go to definition" on a param type t shows 2 definitions - value & type which have same name - even though the value's definition is completely irrelevant.

πŸ™‚ Expected behavior

"Go to definition" shows only relevant definition of type t

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Mar 27, 2024
@ulugbekna
Copy link
Author

Hi @RyanCavanaugh

Thanks for fast triaging! :-)

Wouldn't it count as a bug given value t is not the definition of type t ?

@RyanCavanaugh
Copy link
Member

People complain a lot if the LS doesn't show a reference they think "should" count, but it's generally understood that a human is reading this list and can decide if the found reference is one they care about or not.

@fatcerberus
Copy link

To be specific: the value t "could" count in the case where the code is attempting to emulate a class structure manually (i.e. type t is the class instance type, const t is the static part of the class).

@ulugbekna
Copy link
Author

@ulugbekna
Copy link
Author

People complain a lot if the LS doesn't show a reference they think "should" count, but it's generally understood that a human is reading this list and can decide if the found reference is one they care about or not.

I see, maybe having a setting or running an experiment could help with this? It seems unfortunate that ts-server has to provide incorrect results because of some people's preferences

@snarbies
Copy link

snarbies commented Apr 9, 2024

This sounds like a "cure worse than the disease" type situation.

To be specific: the value t "could" count in the case where the code is attempting to emulate a class structure manually (i.e. type t is the class instance type, const t is the static part of the class).

I couldn't even tell you the number of times I've exported both a constant and a type with the same name because they have a relationship along these lines. Factory function and instance type, interface paired with Math-like utility object, etc.

How frequent and how problematic is the issue of pulling up a type whose name is the same as an unrelated value. I'd expect it to be both rare and inconsequential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants