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

immer.produce has different typings than produce #749

Closed
1 of 3 tasks
ianstormtaylor opened this issue Feb 8, 2021 · 2 comments
Closed
1 of 3 tasks

immer.produce has different typings than produce #749

ianstormtaylor opened this issue Feb 8, 2021 · 2 comments
Labels

Comments

@ianstormtaylor
Copy link
Contributor

馃悰 Bug Report

If you instantiate your own new Immer() instance to keep settings changes local, the immer.produce method doesn't have the same typing information as the top-level produce export.

Link to repro

https://codesandbox.io/s/new-mountain-fq0uw?file=/src/index.ts

import { produce, Immer } from "immer";

const immer = new Immer();
const obj = { a: 1 };

produce(obj, (o) => o);
immer.produce(obj, (o) => o);
                 // ^ Parameter 'o' implicitly has an 'any' type.

With produce the types are as expected. But with immer.produce the draft that gets passed to the callback is of type any instead of Draft.

Environment

We only accept bug reports against the latest Immer version.

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

immer package entry

export const produce: IProduce = immer.produce

export {Immer}

You can noticed that standalone produce function use IProduce typedef, and the Immer instance use raw ts source code typedef.

export class Immer implements ProducersFns {
        /** ommit **/
	produce(base: any, recipe?: any, patchListener?: any) {

So it's infer any type in your case. @mweststrate Sir, Is there any way to declare type correctly?

interface ProducersFns {
	produce: IProduce
	produceWithPatches: IProduceWithPatches
}

I noticed that even we implements ProducersFns, but it's not work as expected when user use new Immer() instance.

@mweststrate
Copy link
Collaborator

馃帀 This issue has been resolved in version 8.0.3 馃帀

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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants