Skip to content

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

Closed
@jcalz

Description

@jcalz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Completion ListsThe issue relates to showing completion lists in an editorEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsFixedA PR has been merged for this issueHelp WantedYou can do thisRescheduledThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions