Value-level generic type names
dead-claudia opened this issue · 4 comments
dead-claudia commented
This is a supplementing proposal to go with my constraint types proposal: #13257, but it also could be very powerful for working with the typeof proposal in #6606.
In that proposal, there is the ability to dispatch type based on value is Whatever, and it would be useful to also generically pass bindings (not just raw types).
Proposal
// Declaration
interface Foo<expr value> {}
type Foo<expr value> = ...
// Declaration with constraints
interface Foo<expr value is Bar> {}
type Foo<expr value is Bar> = ...
// Usage
const foo: Foo<foo>;
declare function bar(item: any): Foo<item>
interface Bar { self: Foo<this>; }- In declarations, you simply prefix
exprto make it a value-level binding rather than a type. - You may constrain these with the same
value is Tsyntax currently available in return values. - Using them is as simple as passing a variable name as a parameter.
- Any
typeofoperand supported is also supported here as a generic parameter. thisis a valid binding.
masaeedu commented
Are you sure 6066 is the right issue number here? It appears to be a PR related to the language service.
dead-claudia commented
RyanCavanaugh commented
I don't understand at all what this is proposing. What is a value-level binding? Is value a special name here? What is this for?
dead-claudia commented
I'm not fully sure either at this point, so I'll close it for now.