Skip to content

Breaking change in produce typescript definition #288

Description

@grassick
  • Issue: Curried TS definition allows undefined to be passed as base
    • Version: 1.10.0
    • Expected behavior: produce currying definition which returns a function that takes a first argument of type Base (the way it used to work before 8666d32)
    • Observed behavior: produce currying definition that returns a function that takes Base | undefined as first parameter

The definition for the curried produce function used to be:

    /** Curried producer with no initial state */
    <State, Result = any, Args extends any[] = any[]>(
        recipe: (
            this: Draft<State>,
            draft: Draft<State>,
            ...extraArgs: Args
        ) => void | Result
    ): (base: State, ...extraArgs: Args) => void extends Result ? State : Result

It is now:

    /** Curried producer */
    <Default = any, Base = Default, Rest extends any[] = [], Return = void>(
        recipe: (
            this: Draft<Base>,
            draft: Draft<Base>,
            ...rest: Rest
        ) => Return,
        defaultBase?: Default
    ): (base: Base | undefined, ...rest: Rest) => Produced<Base, Return>

The fact that the base can be undefined in the returned function messes up existing typescript code that doesn't expect this.

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions