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

Typings of current() don't reflect that returned object is not a draft #896

Open
3 tasks done
robatwilliams opened this issue Jan 17, 2022 · 3 comments
Open
3 tasks done

Comments

@robatwilliams
Copy link

🐛 Bug Report

The typings of current() state that the input and return types are the same. This doesn't reflect that the function unwraps drafts.

Link to repro

const draft = immer.createDraft({ a: true });
immer.current(draft);

To Reproduce

Observe typings of the returned object. Runtime object is not a draft, but typings indicate that it is.

Observed behavior

Return type is the same as the input type.

export declare function current<T>(value: T): T;

Expected behavior

Return type is the type of thing whose draft was input.

export declare function current<T>(value: Draft<T>): T;

Environment

We only accept bug reports against the latest Immer version.

  • Immer version: 9.0.12
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@robatwilliams
Copy link
Author

Same issue with original()

@mweststrate
Copy link
Collaborator

mweststrate commented Jan 18, 2022 via email

@bweis
Copy link

bweis commented Aug 4, 2024

Bumping this. Took a crack at it to no avail.

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

No branches or pull requests

3 participants