Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@devanshj

Description

@devanshj
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.