avenger icon indicating copy to clipboard operation
avenger copied to clipboard

allow void input commands to be called without passing any param

Open giogonzo opened this issue 6 years ago • 2 comments

As per title, a possible (minor?) type-level enhancement. The following tests don't pass with the current command singature:

declare const cvoidf: () => TaskEither<string, number>;
const voidcmd1 = command(cvoidf);
voidcmd1(); // $ExpectType TaskEither<string, number>
voidcmd1({}); // $ExpectError
const voidcmd2 = command(cvoidf, { a });
voidcmd2(); // $ExpectError
voidcmd2(undefined, { a: 'foo' }); // $ExpectType TaskEither<string, number>

Seems fairly easy to do, at the cost of some more unreadable signatures to maintain. E.g., for the first command overload, the return type would become:

: A extends void
  ? (a?: A, ia?: ProductA<I>) => TaskEither<L | IL, P>
  : (a: A, ia?: ProductA<I>) => TaskEither<L | IL, P>;

I'm not sure about the possible negative impacts, I didn't test on real usages yet

giogonzo avatar Oct 12 '19 14:10 giogonzo

voidcmd2(undefined, { a: 'foo' })

seeing this example I wonder if it would be better to have something like

voidcmd2({ params: "param", invalidates: { a: "foo" } }) // when the query has params
voidcmd2({ invalidates: { a: "foo" } }) // when the query does not have params

fes300 avatar Nov 06 '19 16:11 fes300

or maybe a curried version:

voidcmd2("param")({ a: "foo" }) // when the query has params
voidcmd2()({ a: "foo" }) // when the query does not have params

fes300 avatar Nov 06 '19 16:11 fes300