Skip to content

Probable bug: Contextual inference does not work in "object-like" scenariosΒ #44999

Description

Bug Report

πŸ”Ž Search Terms

Contextual inference

πŸ•— Version & Regression Information

tested with 4.4.0-beta

⏯ Playground Link

Playground

πŸ’» Code

createMachine({
  context: { foo: 1 },
  entry: {
    type: "xstate.assign",
    exec: c => ({ foo: c.foo + 1 })
  }
})

createMachine({
  context: { foo: 1 },
  entry: assign(c => ({ foo: c.foo + 1 })) // c is unknown but should be { foo: number } instead
})

declare const createMachine: <C>(defintion: Machine<C>) => {}
type Machine<C> = {
  context: C,
  entry: {
    type: string,
    exec: (context: C) => unknown
  }
}

declare const assign: <C>(f: (context: C) => C) =>
  { type: "xstate.assign", exec: (context: C) => C }

πŸ™ Actual behavior

assign infers type parameter C as unknown

πŸ™‚ Expected behavior

assign should infer type parameter C as { foo: number }

Filing as Ryan said here. Fwiw I think a more minimal repro would be this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions