Closed
Description
🐛 Bug Report
The type definition for applyPatches
changed from 9.0.2 to 9.0.3. I looked at the diff for the 9.0.3 release and don't see anything that would cause this.
diff -r 9.0.2/dist/immer.d.ts 9.0.3/dist/immer.d.ts
47c47
< export declare const applyPatches: (base: import("./internal").Objectish, patches: import("./internal").Patch[]) => any;
---
> export declare const applyPatches: <T extends import("./internal").Objectish>(base: import("./internal").Objectish, patches: import("./internal").Patch[]) => T;
The new type definition is stricter (which is great), but it fails to take advantage of the generic parameter, so it results in TypeScript errors for code that used to work.
I believe that applyPatches
should instead be declared as
applyPatches<T extends Objectish>(base: T, patches: Patch[]): T;
Link to repro
https://codesandbox.io/s/immer-sandbox-forked-y0m5s?file=/src/index.ts
To Reproduce
Infer / implicitly use the return type of applyPatches
.
Observed behavior
A type error occurs, because applyPatches
could return anything.
Expected behavior
Successful compilation, because applyPatches
says it returns its input type.
Environment
- Immer version: 9.0.3
- I filed this report against the latest version of Immer
- Occurs with
setUseProxies(true)
- Occurs with
setUseProxies(false)
(ES5 only)
Activity
fix: Better applyPatches type (#810)
github-actions commentedon Jul 5, 2021
🎉 This issue has been resolved in version 9.0.4 🎉
The release is available on:
Your semantic-release bot 📦🚀