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

No type cast of mapped interface arguments #19023

Closed
johnthecat opened this issue Oct 8, 2017 · 4 comments
Closed

No type cast of mapped interface arguments #19023

johnthecat opened this issue Oct 8, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@johnthecat
Copy link

My current task is writing typings for library, that makes all interface sync methods as async. I found how to cast method result, but I didn't found way to cast argument types.

TypeScript Version: 2.5.3
Code

interface Test {
    method(arg: number /* always 1 argument */): string;
}

type Promisify<T> = {
    [P in keyof T]: (/* cast arguments from T[P] somehow */) => Promise<P[T] /* don't know how it works, maybe it's a bug */>;
}

const test: Promisify<Test>;

test.method(256 /* no autocomplete */).then((data) => {
    console.log(
        data.charCodeAt(0); // works right
    );
});

Expected behavior:
User can get method argument types.

Actual behavior:
Typescript should have some special key for getting method arguments,
something like (args: argumentsof T[P]).

@johnthecat johnthecat changed the title No cast of mapped interface arguments No type cast of mapped interface arguments Oct 8, 2017
@aluanhaddad
Copy link
Contributor

This is not currently supported. Obviously it's very useful behavior and #6606 tracks adding it to the language. I'm not sure why it currently works for return types as the syntax doesn't make any sense. It may be a bug as you say.

@johnthecat
Copy link
Author

@aluanhaddad Linked proposal looks good, but it’s exactly what I want.
In my example with this proposal it should looks like
’’’ts
type Promisify = {
[K in keyof T]: (a: typeof P[T][“arguments”][0] /* wtf? */) => Promise<P[T]>
}
’’’

@mhegazy
Copy link
Contributor

mhegazy commented Oct 9, 2017

#6606 tracks getting the return type, i.e. typeof P[T]()
#12265 tracks the arguments part.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 9, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 23, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Oct 23, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants