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

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

Closed
michelbitter opened this issue Jan 14, 2019 · 2 comments
Closed

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

michelbitter opened this issue Jan 14, 2019 · 2 comments

Comments

@michelbitter
Copy link

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;
}
@aleclarson
Copy link
Member

aleclarson commented Jan 14, 2019

The default behavior of Immer is to freeze any objects it creates a copy of. Before v1.10.3, you were making an invalid assumption that errorMsg would be mutable outside of the producer.

Is there a reason you're not using fully immutable data structures?

Related: #289

aleclarson added a commit that referenced this issue Jan 14, 2019
Redux users may be using Immer without expecting `produce` to have a deeply immutable return type.

Closes #289 #290
@aleclarson
Copy link
Member

🎉 This issue has been resolved in version 1.10.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants