Description
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.