Skip to content

applyPatches type definitions in 9.0.3 #809

Closed
@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)

Activity

added a commit that references this issue on Jun 24, 2021
09ac097
github-actions

github-actions commented on Jul 5, 2021

@github-actions
Contributor

🎉 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @joshkel

      Issue actions

        `applyPatches` type definitions in 9.0.3 · Issue #809 · immerjs/immer