avenger
avenger copied to clipboard
allow void input commands to be called without passing any param
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
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
or maybe a curried version:
voidcmd2("param")({ a: "foo" }) // when the query has params
voidcmd2()({ a: "foo" }) // when the query does not have params