Skip to content

No type cast of mapped interface arguments #19023

Closed
@johnthecat

Description

@johnthecat

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]).

Activity

changed the title [-]No cast of mapped interface arguments[/-] [+]No type cast of mapped interface arguments[/+] on Oct 8, 2017
aluanhaddad

aluanhaddad commented on Oct 8, 2017

@aluanhaddad
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

johnthecat commented on Oct 9, 2017

@johnthecat
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

mhegazy commented on Oct 9, 2017

@mhegazy
Contributor

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

mhegazy

mhegazy commented on Oct 23, 2017

@mhegazy
Contributor

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

locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @aluanhaddad@johnthecat@mhegazy

        Issue actions

          No type cast of mapped interface arguments · Issue #19023 · microsoft/TypeScript