-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Make go to definition go to the constraint's properties for object literals in argument positions #62361
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
Make go to definition go to the constraint's properties for object literals in argument positions #62361
Conversation
…terals in argument positions
| None = 0, | ||
| Signature = 1 << 0, // Obtaining contextual signature | ||
| NoConstraints = 1 << 1, // Don't obtain type variable constraints | ||
| IgnoreNodeInferences = 1 << 2, // Ignore inference to current node and parent nodes out to the containing call for, for example, completions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As shown by this PR, this mechanism is handy for other things than just completions - so I decided to rename it.
src/services/goToDefinition.ts
Outdated
| if (contextualType) { | ||
| return flatMap(getPropertySymbolsFromContextualType(element, typeChecker, contextualType, /*unionSymbolOk*/ false), propertySymbol => getDefinitionFromSymbol(typeChecker, propertySymbol, node)); | ||
| let properties = getPropertySymbolsFromContextualType(element, typeChecker, contextualType, /*unionSymbolOk*/ false); | ||
| if (properties.length === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no way that this would ever apply if there were more than one symbol here? Like, can the definition be both the constraint but also something else via a union?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could come from multiple sources. This is just me using a conservative approach that covers the majority of use cases. I don't see a reason why it wouldn't be OK to change the algorithm to:
- check if
propertiescontain a "self declaration" - if yes then get contextual type with
ContextFlags.IgnoreNodeInferences - if we get some results then get
withoutNodeInferencesPropertiesand if there are some then filter out self-declaration and concat both arrays
This should leave all potential meaningful definitions in the result. WDYT?
A simple playground for experimenting with how TypeScript behaves today in presence of unions: TS playground
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it must be better to not hardcode "exactly one property", but then again I don't know what the change I suggested looks like in code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakebailey I went for quite a simple change here that should address your concern. I can't think of a test case right now that would prove this has to be complicated further.
e9cce24 to
594a01b
Compare
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
No description provided.