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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

original() causes a typescript error #505

Closed
2 tasks done
tmtron opened this issue Jan 14, 2020 · 2 comments
Closed
2 tasks done

original() causes a typescript error #505

tmtron opened this issue Jan 14, 2020 · 2 comments

Comments

@tmtron
Copy link

tmtron commented Jan 14, 2020

馃悰 Bug Report

Link to repro

Stackblitz example

To Reproduce

use the example code from the immer original docs with typescript

const baseState = {users: [{name: "Richie"}]}
const nextState = produce(baseState, draftState => {
	original(draftState.users) // is === baseState.users
}) 

Observed behavior

When using the original() function as described in the docs, we get a typescript error:

Argument of type '{ name: string; }[]' is not assignable to parameter of type 'Drafted<{ name: string; }[], ImmerState>'.
  Property '[DRAFT_STATE]' is missing in type '{ name: string; }[]' but required in type '{ [DRAFT_STATE]: ImmerState; }'.

Expected behavior

No typescript errors

Workaround

cast to any:

	original(draftState.users as any) // is === baseState.users

Environments

  • Immer version:
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@mweststrate
Copy link
Collaborator

This is a regression indeed, will be fixed in 5.3 through #506

@tmtron
Copy link
Author

tmtron commented Jan 15, 2020

Thanks, that was fast!
just updated to 5.3.0 and can confirm that this works now.

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