Skip to content

[1.10.4] returned type isn't as expected #290

@michelbitter

Description

@michelbitter

After updating Immer to version 1.10.4. I'm running into a couple of typing errors on typescript.

example code:

import produce from 'immer'

export interface ConditionHandlerOutput {
  readonly errorMsg: string[],
  readonly success: boolean,
}

const stateList: ConditionHandlerOutput[] = []

// `x` cannot be modified here
const state: ConditionHandlerOutput = {
  errorMsg: [],
  success: true,
}

const newState = produce(state, draft => {
  // `x` can be modified here
  draft.errorMsg.push('This is a random string')
  draft.success = false
})

stateList.push(newState)

Expected behaviour: newState has type: ConditionHandlerOutput

Observed behavior: newState hasn't the expected type and given type is not comparable. Returned typ is:

const newState: {
    readonly errorMsg: ReadonlyArray<string>;
    readonly success: boolean;
}

Metadata

Metadata

Assignees

No one assigned

    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