Skip to content

Typeguards in match of split are not working in config overload #769

@AlexandrHoroshih

Description

@AlexandrHoroshih

What is the current behavior:
Currently typeguards in match field are not working in split

Following code

const $s = createStore<string | null>(null)
const valid = createEvent<string>()

const clk = createEvent()

split({
    source: $s,
    clock: clk,
    match: {
        valid: (str: string | null): str is string => Boolean(str),
    },
    cases: {
        valid,
    }
})

gives type error like { error: "source type should extends cases"; sourceType: string | null; caseType: string; }

It can be workarounded by using other overload, where split actually creates events based on match typings

const $s = createStore<string | null>(null);
const valid = createEvent<string>();

const clk = createEvent();

const { validCase } = split(
  sample({ source: $s, clock: clk }),
  {
    validCase: (str: string | null): str is string =>
      Boolean(str),
  }
);

sample({
  clock: validCase,
  target: valid,
});

Please provide the steps to reproduce and if possible a minimal demo of the problem via https://share.effector.dev, https://codesandbox.io or similar

What is the expected behavior:

  • Typeguards in match of config form of split are working

Which versions of effector packages, and which browser and OS are affected by this issue? Did this work in previous versions of effector?:
current latest release of effector@22

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtypingsTypescript public type definitions issues

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions