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

infer the wrong type when returntype of produce callback is any #785

Closed
hardfist opened this issue Apr 19, 2021 · 1 comment
Closed

infer the wrong type when returntype of produce callback is any #785

hardfist opened this issue Apr 19, 2021 · 1 comment
Labels

Comments

@hardfist
Copy link
Contributor

馃悰 Bug Report

import { produce, Draft } from 'immer';
const x = { a: 1 };

function wrapper<T>(s: T, fn: (d: Draft<T>) => void) {
  const result = produce(s, (y) => {
    return fn(y);
  });
  return result;
}

function wrapper2<T>(s: T, fn: (d: Draft<T>) => any) {
  const result = produce(s, (y) => {
    return fn(y);
  });
  return result;
}
const res = wrapper(x, (y) => {
  y.a = 1;
}); // {a:number}
const res2 = wrapper2(x, (y) => {
  y.a = 2;
}); // Promise<{a:number}>
res2.then(x => {
    console.log('x:',x) // crash
})
console.log(x, res, res2);

Link to repro

https://www.typescriptlang.org/play?#code/PTAEAEBcGcFoGMAWBTeBrAUASwLYAcB7AJ0lAG9Q8iCATAV3mQBpQARIgQwDNSBfULtRygA5LhzIiIgNwZ4BAHbRSAD1ABecqA4AuUAEZQvWfKWkAnhsrV6jABQqWdmgEoNAPnIZQoGgDoOKwAmWV4XWS46BXhILEVQAHdOPDxJAB4AFXc7aD0Mli4FPWc9dm5ITPc3dU8ANwIsVy8fU2VQImRoOgAbUk0qWgZkHKdzas8ybx925Eg6IgUBBTsx2R8wtZm5hZmu3tCMDEjo2PikjhTJIMqcvIKi0BK2Th5K8e0FMebQVtIOvb61kG9mgo3ek2mW3mi0KK3CUw2Uw620W-x6kAOv12VnOlyIDjBHm+5gCVn0oXCoBA5F0CjoOAARpJeHJFG1-kEcclUkQggTHl8asTSZoQhgNlSwAAFIRYaDINJkWn0plEXjuVlKAjdZB+boEADm-PMLH+ps6QXhQA

hardfist added a commit to hardfist/immer that referenced this issue Apr 19, 2021
hardfist added a commit to hardfist/immer that referenced this issue Apr 19, 2021
@mweststrate
Copy link
Collaborator

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

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

2 participants