-
Notifications
You must be signed in to change notification settings - Fork 12.8k
infer the spread operator function parameter names and types, via generic type extraction #25634
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
Comments
Their is a small corner case now that I think of it for the following cases, were only paramA is used, then I need a way to differentiate be able to extracted params from a function base on their position, to be able to compute the overlap, by saying , there is ambiguity, if the first generic extracted param is a string and it matches that of first key, then their is a corner case that undefined type would need to be supplied for M. So basically the function signature becomes somthing like this. So this requires at least one more features request to fully work, that genric extends for M, be allowed to be evaluated conditions using extends to determine its type, I need to double check this fact.. never tried it before, if it works all great! function Promisifiy<R, O,
M extends keyof O ? keyof O : O extends (A: infer, ..args: any []) =>void? A : undefined,
A = ExtractParamsAndTypes<M extends keyof O ? O[K]] : DropFirstParam<O[K]>>
(obejct: O, keyMethod : M, ... args : A) :
: R extends undefined ? ExtractBlueBirdCallbackResults<O[M]> : BlueBird<R>
{}
Type DropFirstParam<T extends Function> = T extends (paramA : any, args : infer R) => any? R : never casesCase A , when function signature is conventional/compliant for the types definitions.interface Actually
{
resultA : string,
restultB : number
}
const myMethodPromise = Promisify(lib.myMethod, 'paramA', 'paramB',' 'ParamC');
myMethodPromise.then(r => r.resultsA || r.resultsB); Case B, Overide the return typeinterface Overide
{
OverideA : string,
OverideB : number
}
const myMethodPromiseOverideResult = Promisify<Overide>(lib.myMethod, 'paramA', 'paramB',' 'ParamC');
myMethodPromiseOverideResult.then(r => r.OverideA || r.OverideB); |
Part of this proposal is covered by #24897. We are working next on 1. enabling mapping on tuples/array types (today that is restricted to object types), and 2. adding higher order operators to spread and extract/infer types from tuples. |
@mhegazy Are there issues tracking these that we can watch? A quick search on my part didn't find anything. :) |
@mhegazy Hey, use search did return anything for me either. But I guess best that you guys, are able to have birds eye view of everything, which means, you just merge the posts, cause everyone has their own ideas and way to describe things. Still got 3 more bugs to log and features.. get to that to day, hopefully. |
This is an additional feature request that builds on functionality here: |
One could also look at writing the constraint in reverse, like in this post, however, their cons to that and advantages to being able to write the constraints in the forward direction. |
not yet. we have discussed these as part of the tuples but have not logged anything yet. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
I would like the ability to be able to re-write and wrap code correctly for promises and similar things,
with out having to have a whole bunch of intermediate statements function calls, when could be done in one statement, but then I need the typing system to support the ability to be able to do that.
Their are 3 Features in this request, in priority order, were we can polyfill the rest with copy and past in the mean time.
Extract Parameter Names And Types from a function
Conditional Generic extends constraint.
Extract types based on a key position
Infer the parameters of the spread operator
Resulting use cases
Case A , when function signature is conventional/compliant for the types definitions.
Case B, Overide the return type
The text was updated successfully, but these errors were encountered: