Skip to content
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

Generic interface with generic type parameter as another generic interface without declared parameter #39536

Closed
archfz opened this issue Jul 9, 2020 · 4 comments

Comments

@archfz
Copy link

archfz commented Jul 9, 2020

Search Terms

generic parameter for interface as another generic interface
generic interface parameter nesting
generic interface with proxied generic parameter

Suggestion

I would like to be able to define a generic interface T where X would be another generic interface and to be able to restrict how many generic parameters it would provide. Maybe best I could write it as interface T<X<any>> to require 1 generic type with 1 generic parameter, but that parameter would have to be added not in the declaration of the interface but in the declarations inside the body of the interface.

Use Cases

An example use case would be of having a provider that serves some types A, B, C wrapped in another object that can have a generic type ParameterBag.

interface Provider<ParameterBag<any>> {
  getA(): ParameterBag<A>
  getB(): ParameterBag<B>
  getC(): ParameterBag<C>
} 

interface ParmeterBagKind<T> { }
class ProviderKind implements Provider<ParmeterBagKind> { }

Checklist

My suggestion meets these guidelines:

  • [ x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ x ] This wouldn't change the runtime behavior of existing JavaScript code
  • [ x ] This could be implemented without emitting different JS based on the types of the expressions
  • [ x ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [ x ] This feature would agree with the rest of TypeScript's Design Goals.
@jcalz
Copy link
Contributor

jcalz commented Jul 9, 2020

Duplicate of #1213

@archfz
Copy link
Author

archfz commented Jul 9, 2020

Is there a typescript vocabulary that gives all of these words for the generic typing specifics? Searching for existing issue for this was hard for me because I was not able to construct with proper names what I would like.

@archfz
Copy link
Author

archfz commented Jul 9, 2020

Also I will close this as of duplicate.

@archfz archfz closed this as completed Jul 9, 2020
@jcalz
Copy link
Contributor

jcalz commented Jul 10, 2020

Is there a typescript vocabulary that gives all of these words for the generic typing specifics? Searching for existing issue for this was hard for me because I was not able to construct with proper names what I would like.

Not that I know of; the only reason I knew this was a duplicate is because I remembered the existing issue. In other languages this is usually called "higher kinded types" but I don't know if there's a single canonical terminology for this or anything else in TypeScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants