Skip to content

applyPatches type definitions in 9.0.3 #809

@joshkel

Description

@joshkel

🐛 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions