Commit 4d28559
Fix ES2015 built-in type errors in consumers by adding lib reference directive to published declarations (#558)
Consumers using `"lib": ["ES5", "DOM"]` (or omitting `lib` entirely) get
TypeScript errors like `Cannot find name 'Symbol'` / `Cannot find name
'Iterator'` because the package's published `.d.ts` file references
ES2015 built-ins without declaring that dependency to TypeScript.
## Root Cause
The bundled declaration file (`lib/dist/types/ts-utils.d.ts`) exposes
ES2015 types such as `Symbol`, `Iterator<T>`, `Iterable<T>`,
`IterableIterator<T>`, and `Promise<T>` in its public API surface.
Without a `/// <reference lib="es2015" />` directive in the published
file, consumers must manually add `"lib": ["ES2015"]` to their own
`tsconfig.json` — otherwise TypeScript cannot resolve these types.
## Changes
- **`lib/src/index.ts`** and **`lib/src/polyfills.ts`** — adds `///
<reference lib="es2015" />` to the source entry points so TypeScript
includes the directive in generated `.d.ts` files and validates against
ES2015 types at build time
- **`lib/scripts/setTsReferences.js`** — new post-processing script that
prepends `/// <reference lib="es2015" />` to the api-extractor bundled
output (`lib/dist/types/ts-utils.d.ts`); this is required because
api-extractor strips `/// <reference lib="..." />` directives from its
rollup
- **`package.json`** — updates the `dtsgen` script to `api-extractor run
--local --verbose && node lib/scripts/setTsReferences.js` so the
post-processing runs automatically as part of every build
- **`lib/tsconfig.base.json`** — adds `"lib": ["ES2015", "DOM"]`;
propagates to both the ES5 and ES6 build configs via `extends`
- **`lib/test/tsconfig.test.json`**,
**`lib/test/tsconfig.test.karma.json`**,
**`lib/test/tsconfig.worker.karma.json`** — add `"lib": ["ES2015",
"DOM"]`
- **`lib/test/tsconfig.test.esnext.json`** — adds `"lib": ["ESNext",
"DOM"]`
- **`CHANGELOG.md`** — adds bug fix entry for v0.13.0
The net effect is that consumers who import from `@nevware21/ts-utils`
automatically get the ES2015 type definitions included by TypeScript —
no change to their own `tsconfig.json` is required.
`DOM` is included alongside `ES2015` in all tsconfig files because the
public API exports types like `Window`, `Document`, `Navigator`, and
`History` (from `helpers/environment.ts`), which require the DOM lib to
resolve.
This does not change the JavaScript runtime target or emit.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>1 parent da838a4 commit 4d28559
10 files changed
Lines changed: 58 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
5 | 12 | | |
6 | 13 | | |
7 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| |||
0 commit comments