You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a function that takes an input object, adds properties to it based on the arguments, and returns it. In this case, the argument is a string containing multiple key-value pairs, but if I know what those keys are, I can tell the type checker what type is going to be returned. But I don't feel like declaring the input type twice, since it be an object literal, as seen here.
declare function parseFields<S, T = {}>(text: string, result: T): typeof result & S;
//returns a type with two fields, not three
parseFields<{hello:string, world:string}>("hello=there&world=here", { hi: 'there' })
Instead of T = {}, I want to somehow tell it that it is supposed to infer it from result, yet still be able to specify S. I'm putting this in as a feature request, because I'm pretty sure there is no way to do this.
T = typeof result gives me the error that result cannot be found. Yet, I think that this might be the best way to imply this, although I don't know how that would fit into the overall flow. What about T = typeofarg result or T = typeof arg result?
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
I have a function that takes an input object, adds properties to it based on the arguments, and returns it. In this case, the argument is a string containing multiple key-value pairs, but if I know what those keys are, I can tell the type checker what type is going to be returned. But I don't feel like declaring the input type twice, since it be an object literal, as seen here.
Instead of
T = {}
, I want to somehow tell it that it is supposed to infer it from result, yet still be able to specify S. I'm putting this in as a feature request, because I'm pretty sure there is no way to do this.T = typeof result
gives me the error thatresult
cannot be found. Yet, I think that this might be the best way to imply this, although I don't know how that would fit into the overall flow. What aboutT = typeofarg result
orT = typeof arg result
?The text was updated successfully, but these errors were encountered: