Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split cases show error with inline prepend calls #999

Open
zerobias opened this issue Oct 22, 2023 · 1 comment
Open

split cases show error with inline prepend calls #999

zerobias opened this issue Oct 22, 2023 · 1 comment
Labels
core effector package typings Typescript public type definitions issues

Comments

@zerobias
Copy link
Member

When event created by prepend directly in cases object, it shows errors in any cases, but everything works ok when unit or cases object created in separated variable

This not works:

split({
  source: fooFx.failData,
  match: (res) => 'ok',
  cases: {
    __: errorSettled.prepend(() => 'ok')
  }
})

This works:

const resultTarget = errorSettled.prepend(() => 'ok')

split({
  source: fooFx.failData,
  match: (res) => 'ok',
  cases: {
    __: resultTarget
  }
})
const cases = {
  __: errorSettled.prepend(() => 'ok')
}

split({
  source: fooFx.failData,
  match: (res) => 'ok',
  cases
})

Link to TS repl

@zerobias zerobias added typings Typescript public type definitions issues core effector package labels Oct 22, 2023
@L117
Copy link

L117 commented Dec 2, 2023

This is a TypeScript type inference nuance, cases in this case (No puns intended) is something like Record<string, Event<T>>. This issue can be easily solved by adding as const like this:

split({
  source: fooFx.failData,
  match: (res) => 'ok',
  cases: {
    __: errorSettled.prepend(() => 'ok')
  } as const
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core effector package typings Typescript public type definitions issues
Projects
None yet
Development

No branches or pull requests

2 participants