Commit b00474e
authored
fix: remove global
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 #1273var Iterator declaration conflicting with ESNext lib (#1290)1 parent 6c7a3de commit b00474e
1 file changed
Lines changed: 12 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
176 | | - | |
177 | | - | |
| 178 | + | |
| 179 | + | |
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
| |||
0 commit comments