Closed
Description
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])
.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]No cast of mapped interface arguments[/-][+]No type cast of mapped interface arguments[/+]aluanhaddad commentedon Oct 8, 2017
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 commentedon Oct 9, 2017
@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 commentedon Oct 9, 2017
#6606 tracks getting the return type, i.e.
typeof P[T]()
#12265 tracks the arguments part.
mhegazy commentedon 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.