patronum icon indicating copy to clipboard operation
patronum copied to clipboard

`delay` doesn't allow to use `void` in `target`

Open mindyourlifeguide opened this issue 3 years ago • 7 comments

The effect in the target expects void, a conditional number arrives from doneData - a mismatch in delay types

example:

delay({
    source: someFirstFx.doneData,
    timeout: 1000,
    target: someSecondFx,
});

mindyourlifeguide avatar Aug 31 '22 08:08 mindyourlifeguide

Could you add a reproduce in https://www.typescriptlang.org/play ?

sergeysova avatar Sep 01 '22 08:09 sergeysova

@sergeysova check this

mindyourlifeguide avatar Sep 01 '22 08:09 mindyourlifeguide

the second effect takes data from the store via attach

mindyourlifeguide avatar Sep 01 '22 08:09 mindyourlifeguide

maybe in delay we need to be able to choose between source/clock?

mindyourlifeguide avatar Sep 01 '22 08:09 mindyourlifeguide

Okay, I transformed your example into minimal reproduce:

import { delay } from 'patronum';
import { createEvent } from 'effector';

const input = createEvent<string>()
const output = createEvent<void>();

delay({
    source: input,
    timeout: 1000,
    target: output,
});
Type 'Event<void>' is not assignable to type 'Event<string> | Store<string> | Effect<string, any, any> | undefined'.
  Type 'Event<void>' is not assignable to type 'Event<string>'.
    Types of property 'watch' are incompatible.
      Type '(watcher: (payload: void) => any) => Subscription' is not assignable to type '(watcher: (payload: string) => any) => Subscription'.
        Types of parameters 'watcher' and 'watcher' are incompatible.
          Types of parameters 'payload' and 'payload' are incompatible.
            Type 'void' is not assignable to type 'string'.(2322)
index.d.ts(6, 5): The expected type comes from property 'target' which is declared here on type '{ source: Unit<string>; timeout: number | Store<number> | ((_payload: string) => number); target?: Event<string> | Store<string> | Effect<string, any, any> | undefined; }'

Try it

sergeysova avatar Sep 01 '22 13:09 sergeysova

more complete example

mindyourlifeguide avatar Sep 07 '22 12:09 mindyourlifeguide

You could solve it in userland. Something like this will work.

delay({
  source: sample({
    clock: input,
    fn: () => {},
  }),
  timeout: 1000,
  target: output,
});

k0lyan avatar Sep 28 '22 05:09 k0lyan