Improve type signature for `void` RPCs
sodic opened this issue · comments
Filip Sodić commented
For any void
backend Operation, such as:
export const getAnything: GetAnything = async () => {
return 'anything'
}
The inferred payload type is args: void
. Calling Parameters<typeof getAnything>
returns [args?: void | undefined]
:
// What we have
type Params = Parameters<typeof getAnything> // Params = [args?: void | undefined]
getAnything() // works
getAnything(undefined) // works
// What we want
type Params = Parameters<typeof getAnything> // Params = []
getAnything() // works
getAnything(undefined) // doesn't work
It works well enough for most use cases, but is not 100% correct (i.e., it will allow a call without arguments, but will also allow a call with undefined
).