Closed
Description
Search Terms
Suggestion
Allow generic consumer to pass generic argument by name, for instance:
interface Provider<Foo, Bar, Baz, Qux, Quux, ...> {
foo: Foo
bar: Bar
tup: [Baz, Qux, Quux]
...
}
type Consumer = Provider<
Foo = number,
Bar = string,
...
>
let consumer: Provider<
Foo = {},
Bar = [],
...
>
This would allow us to write and use a generic with thousands of parameter without decreasing readability.
NOTES
- Before you ask, this feature request is not a duplicate of Proposal: allow type arguments of generic being named #22631 in any shape or form.
- This is similar to keyword (named) arguments in Python.
- Vanilla JavaScript doesn't need keyword arguments as it already has objects, but there's no equivalent for TypeScript generic arguments.
Use Cases
Above
Examples
Above
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. new expression-level syntax)