Skip to content

Completion list should include property names of constraining type when writing object type literals in type argument positions #33302

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
5 tasks done
jcalz opened this issue Sep 8, 2019 · 3 comments
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Fixed A PR has been merged for this issue Help Wanted You can do this Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript

Comments

@jcalz
Copy link
Contributor

jcalz commented Sep 8, 2019

Search Terms

completion list, IntelliSense, keys, members, generic constraint,

Suggestion with Example

It would be nice to get some IntelliSense help when specifying the members of a constrained object type. For example, given these types:

interface Foo {
  apple: string;
  banana: number;
  cherry: boolean;
}

interface SomeGeneric<F extends Foo> {
  foo: F;
}

I was kind of expecting to be given some hints about what keys I needed when writing this:

declare const s: SomeGeneric<{
  apple: "hey";
  banana: 123;
  // <-- no IntelliSense here for anything but "readonly"
}>;

Instead, I only seem to get a suggestion for readonly. It would be very helpful if apple, banana, and cherry were part of the completion list.

Use Cases

I would think this is useful anytime you're specifying a constrained generic parameter, or possibly even extending an existing interface. Its absence is painful in any case where the generic type has lots of members, as in this Stack Overflow question.

Related Issues

Possibly related to #1506?

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript labels Sep 12, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 12, 2019
@RyanCavanaugh RyanCavanaugh changed the title Completion list for members when specifying constrained generic? Completion list should include property names of constraining type when writing object type literals in type argument positions Sep 12, 2019
@DanielRosenwasser DanielRosenwasser added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels Jan 28, 2021
@williamluke4
Copy link

@DanielRosenwasser If someone can point me in the right direction. I don't mind having a go at implementing this

@DanielRosenwasser
Copy link
Member

@williamluke4 sorry I missed your message. There is currently another community PR that seems like it's on the right track if you're still interested in contributing and want to get a good handle on what the work here involves.

@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Apr 20, 2021
@DanielRosenwasser
Copy link
Member

Fixed by #43526. Thanks @tiagovtristao!

@DanielRosenwasser DanielRosenwasser added the Domain: Completion Lists The issue relates to showing completion lists in an editor label Apr 20, 2021
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Fixed A PR has been merged for this issue Help Wanted You can do this Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants