Skip to content

Conflict between TS global Iterator definition and ESNext lib #1273

Description

@OmniSliver

🐛 Bug Report

There is a conflict between the global Iterator type introduced in immer v11.1.11 and the default Iterator type in TypeScript's ESNext lib.

The whole error:

node_modules/immer/dist/immer.d.ts:214:9 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'Iterator' must be of type 'IteratorConstructor', but here has type '{ from<T, TReturn>(iterable: Iterator<T, TReturn, any>): IterableIterator<T>; } | undefined'.

214     var Iterator: undefined | {
            ~~~~~~~~

  node_modules/@typescript/typescript-linux-x64/lib/lib.es2025.iterator.d.ts:145:9 - 'Iterator' was also declared here.
    145     var Iterator: IteratorConstructor;
                ~~~~~~~~


Found 1 error in node_modules/immer/dist/immer.d.ts:214

Link to repro

https://github.com/OmniSliver/immerGlobalIterator

(I don't know how to run the TypeScript checker in codesandbox)

To Reproduce

Steps to reproduce the behavior:

  • npm ci
  • npm run ts

Observed behavior

I get an error when running the TypeScript checker using the ESNext lib option

Expected behavior

To not get the error.

Environment

We only accept bug reports against the latest Immer version.

  • Immer version: v11.1.15, but introduced in v11.1.11
  • 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

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions