fix: remove global `var Iterator` declaration conflicting with ESNext lib (#1290)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
The `declare global { var Iterator }` shim (added to feature-detect ES2025's `Iterator.from`) leaks a global variable declaration into the bundled `dist/immer.d.ts`. When a consumer compiles against the `esnext` lib, tsc reports: 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>): IterableIterator<T> } | undefined'. Replace the global augmentation with a module-scoped feature detect that reads the iterator constructor off `globalThis`. The runtime behavior is unchanged (uses `Iterator.from` when available, falls back to the manual iterator), but the emitted `.d.ts` no longer declares a global that clashes with the standard library. Fixes #1273
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+12 added−10 removed
- other:+12 added−10 removed