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

applyPatches type definitions in 9.0.3 #809

Closed
1 of 3 tasks
joshkel opened this issue Jun 10, 2021 · 1 comment 路 Fixed by #810
Closed
1 of 3 tasks

applyPatches type definitions in 9.0.3 #809

joshkel opened this issue Jun 10, 2021 · 1 comment 路 Fixed by #810
Labels

Comments

@joshkel
Copy link
Contributor

@joshkel joshkel commented Jun 10, 2021

馃悰 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)
mweststrate pushed a commit that referenced this issue Jun 24, 2021
applyPatches should specify its input as type `T` so that TypeScript can better infer the correct `T` for its output.

Fixes #809
@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Jul 5, 2021

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

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

Successfully merging a pull request may close this issue.

1 participant