-
-
Notifications
You must be signed in to change notification settings - Fork 850
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
draft
is typed as any
when using produce()
within React setState()
#720
Comments
Might suffer from the same problem as demonstrated in this playground, meaning we could possibly apply the same solution. See also: mobxjs/mobx#2740 |
typedef changeBefore v2.1.5 https://github.com/immerjs/immer/blob/v2.1.5/src/immer.d.ts#L71-L107 > v2.1.5 <
Recipe extends (...args: any[]) => any,
Params extends any[] = Parameters<Recipe>,
T = Params[0]
>(
recipe: Recipe
): <Base extends Immutable<T>>(
base: Base,
...rest: Tail<Params>
) => Produced<Base, ReturnType<Recipe>> recipe => Recipe => <= v2.1.5 /** Curried producer with no default value */
<T = any, Rest extends any[] = [], Return = void>(
recipe: (this: Draft<T>, draft: Draft<T>, ...rest: Rest) => Return
): (base: Immutable<T>, ...rest: Rest) => Produced<T, Return> recipe => @mweststrate Sir, Maybe this is why current version append
function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
type Dispatch<A> = (value: A) => void;
type SetStateAction<S> = S | ((prevState: S) => S); |
🎉 This issue has been resolved in version 9.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🐛 Bug Report
draft
is typed asany
when usingproduce()
within ReactsetState()
, instead of inferring the type. Older versions ofimmer
does this properly, but newer one doesn't. As far as I can see, v2.1.5 (and before) works, after that it doesn't.Link to repro
Working:
https://codesandbox.io/s/adoring-https-rsgqg?file=/src/App.tsx
Not working (only change is version of
immer
to v8.0.0):https://codesandbox.io/s/flamboyant-lehmann-ms3fw?file=/src/App.tsx
Expected behavior
I expect the
draft
to get a proper type.Environment
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: