Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

allow void input commands to be called without passing any param #204

Open
giogonzo opened this issue Oct 12, 2019 · 2 comments
Open

allow void input commands to be called without passing any param #204

giogonzo opened this issue Oct 12, 2019 · 2 comments

Comments

@giogonzo
Copy link
Member

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

@fes300
Copy link
Contributor

fes300 commented Nov 6, 2019

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
Copy link
Contributor

fes300 commented Nov 6, 2019

or maybe a curried version:

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants