Skip to content

Conversation

@Andarist
Copy link
Contributor

No description provided.

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
Copy link
Contributor Author

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.

GameRoMan

This comment was marked as 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) {
Copy link
Member

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?

Copy link
Contributor Author

@Andarist Andarist Dec 4, 2025

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 properties contain a "self declaration"
  • if yes then get contextual type with ContextFlags.IgnoreNodeInferences
  • if we get some results then get withoutNodeInferencesProperties and 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

Copy link
Member

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.

Copy link
Contributor Author

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.

@Andarist Andarist force-pushed the gotodef-obj-literal-constraint-def branch from e9cce24 to 594a01b Compare December 5, 2025 16:44
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 5, 2025
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@Andarist Andarist requested a review from jakebailey December 8, 2025 08:31
@github-project-automation github-project-automation bot moved this from Not started to Needs merge in PR Backlog Dec 8, 2025
@jakebailey jakebailey merged commit b2327c0 into microsoft:main Dec 8, 2025
33 checks passed
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants