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 constraint for mapped property #12381

Closed
dead-claudia opened this issue Nov 19, 2016 · 2 comments
Closed

Generic constraint for mapped property #12381

dead-claudia opened this issue Nov 19, 2016 · 2 comments

Comments

@dead-claudia
Copy link

dead-claudia commented Nov 19, 2016

I need to constrain a mapped property so I can basically get the return type out of its methods and modify it. Here's the gist of the two transformations I need to type (I need both):

interface Original<T> {
  [P in keyof T](...args): R;
}

interface Wrapped<T> {
  [P in keyof T](...args): Promise<R>;
}

interface Proxied<T> {
  call<P extends keyof T>(method: P, ...args): Promise<R>;
}

export function wrap<T extends Original<T>>(original: T): Wrapped<T>;
export function proxy<T extends Original<T>>(original: T): Proxied<T>;

I know TypeScript 2.1's mapped properties aren't enough, so any ideas?

@dead-claudia
Copy link
Author

Note: the return types are not necessarily the same across multiple methods.

@aluanhaddad
Copy link
Contributor

See also #12342

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

No branches or pull requests

2 participants