Skip to content

Suggest completions for type arguments of expressions #61758

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mkantor
Copy link
Contributor

@mkantor mkantor commented May 23, 2025

Completions are now suggested within type arguments of the following expression types (based on type parameter constraints):

  • function calls (f<…>())
  • new expressions (new Foo<…>())
  • tagged templates (tag<…>`blah`)
  • JSX elements (<Component<…>/>)
  • decorators (@decorator<…> class {})
  • instantiation expressions (f<…>)

Fixes #61751.

Limitations

This comment may also be useful reading.

This internal utility function and corresponding type weren't in use,
and `hasTypeArguments`'s guarding was buggy:

- `node` could be a `NodeWithTypeArguments`, which is not a member of
  `HasTypeArguments`
- else branch narrowing was wrong: `typeArguments` is optional, so it
  can be undefined while `node` is assignable to `HasTypeArguments`
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog May 23, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label May 23, 2025
@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

Comment on lines -4754 to -4757
/** @internal @knipignore */
export function hasTypeArguments(node: Node): node is HasTypeArguments {
return !!(node as HasTypeArguments).typeArguments;
}
Copy link
Contributor Author

@mkantor mkantor May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This internal utility function was unused, and I noticed it had buggy guarding semantics which tripped me up when I tried to use it:

  • node could be a NodeWithTypeArguments, which is not a member of HasTypeArguments
  • else branch narrowing was wrong: typeArguments is optional, so it can be undefined while node is still assignable to HasTypeArguments

The former is trivially fixable while the latter is not, so I opted to purge this to avoid future confusion. Let me know if I should do something else instead.

Comment on lines -1296 to -1301
export type HasTypeArguments =
| CallExpression
| NewExpression
| TaggedTemplateExpression
| JsxOpeningElement
| JsxSelfClosingElement;
Copy link
Contributor Author

@mkantor mkantor May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this along with the hasTypeArguments guard, but I think this type is public and if there's a chance this might cause breakage somewhere I could restore it (even if the internal hasTypeArguments function remains purged).

If I do restore it, perhaps NodeWithTypeArguments should be added to the union?

Previously, `getTypeArgumentConstraint` could only find constraints for
type arguments of generic type instantiations. Now it additionally
supports type arguments of the following expression kinds:

- function calls
- `new` expressions
- tagged templates
- JSX expressions
- decorators
- instantiation expressions
@mkantor mkantor force-pushed the completions-of-type-arguments-in-more-places branch from d01431a to e4bac38 Compare May 24, 2025 15:23
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: Not started
Development

Successfully merging this pull request may close these issues.

Completions for type arguments of expressions
2 participants