Replies: 1 comment 1 reply
-
See this comment here: the array is just a type trick to determine whether or not the 2nd param is required for GET requests: It’s basically an alternate method to declaring function overloads for GET, which would result in more complex inference. It’s not actually an array; it’s just a way for TS to not require you putting I’m not sure what the issue is; this seems more like a discussion so I’ll move it there. But If I’m missing something please let me know! And/or providing a failing test would be helpful. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
In the type definition of
ClientMethod
,init
parameter is a rest parameter (...init
), and its type isMaybeOptionalInit<Paths[P], M>
, which is an Array.However, when this type is used, in
createClient
, only the first element is ever used in the return value.For example:
This is because
init
in the implementation of POST (and of all the other methods) is not a rest parameter, and so it only captures the first value.The
MaybeOptionalInit
is actually always an array of 1 element (and the type is defined as such). However, when the type is captured, it's not obvious in all contexts.Reproduction
It's a type issue, so it nothing happens at runtime.
Expected result
MaybeOptionalInit
looks like it could be a simple value, not an Array. It would make it easier to capture the types of the parameters when wrapping theClient
object into a decorator.Checklist
Beta Was this translation helpful? Give feedback.
All reactions