Skip to content

Fix ES2015 built-in type errors in consumers by adding lib reference directive to published declarations#558

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-compilation-errors-nevware21
Open

Fix ES2015 built-in type errors in consumers by adding lib reference directive to published declarations#558
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-compilation-errors-nevware21

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

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.

Copilot AI changed the title [WIP] Fix compilation errors for nevware21 type definitions Add explicit ES2015 lib to tsconfig files May 14, 2026
Copilot AI requested a review from nev21 May 14, 2026 02:54
Copilot finished work on behalf of nev21 May 14, 2026 02:54
@nev21 nev21 marked this pull request as ready for review May 14, 2026 03:00
@nev21 nev21 requested review from a team as code owners May 14, 2026 03:00
Copilot AI review requested due to automatic review settings May 14, 2026 03:00
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.46%. Comparing base (da838a4) to head (287c358).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #558   +/-   ##
=======================================
  Coverage   99.46%   99.46%           
=======================================
  Files         145      145           
  Lines        4271     4271           
  Branches      938      938           
=======================================
  Hits         4248     4248           
  Misses         23       23           
Files with missing lines Coverage Δ
lib/src/polyfills.ts 94.11% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the required TypeScript standard library typings explicit across the library build and test tsconfig files by declaring ES2015 (and ESNext for ESNext tests) alongside DOM, preventing missing built-in type errors during compilation.

Changes:

  • Add "lib": ["ES2015", "DOM"] to the shared lib/tsconfig.base.json so it propagates to the library build configs via extends.
  • Add "lib": ["ES2015", "DOM"] to the ES5-oriented test tsconfigs (Node + Karma runner configs).
  • Add "lib": ["ESNext", "DOM"] to the ESNext test tsconfig.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/tsconfig.base.json Declares ES2015 + DOM libs for the base compiler config used by library builds.
lib/test/tsconfig.worker.karma.json Declares ES2015 + DOM libs for worker Karma test compilation.
lib/test/tsconfig.test.karma.json Declares ES2015 + DOM libs for browser Karma test compilation.
lib/test/tsconfig.test.json Declares ES2015 + DOM libs for Node/common test compilation via ts-mocha.
lib/test/tsconfig.test.esnext.json Declares ESNext + DOM libs for ESNext test compilation.

@nev21
Copy link
Copy Markdown
Contributor

nev21 commented May 14, 2026

@copilot This is only addressing the local test resources and not the actual reported issue.
Also update the change list / log

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

@copilot This is only addressing the local test resources and not the actual reported issue.
Also update the change list / log

Addressed in commit 337e0e8. The actual fix is a /// <reference lib="es2015" /> directive added to the published bundled declaration file (lib/dist/types/ts-utils.d.ts). When consumers import from the package, TypeScript automatically includes ES2015 type definitions — so they no longer need to add "lib": ["ES2015"] to their own tsconfig.

The implementation:

  • Added /// <reference lib="es2015" /> to lib/src/index.ts and lib/src/polyfills.ts for build-time validation
  • Created lib/scripts/setTsReferences.js as a post-processing step, since api-extractor strips reference lib directives from its bundled rollup output
  • Updated the dtsgen npm script to run the post-processor after api-extractor
  • Updated CHANGELOG.md with the bug fix entry

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.googleapis.com
    • Triggering command: /usr/local/bin/node node install.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add explicit ES2015 lib to tsconfig files Fix ES2015 built-in type errors in consumers by adding lib reference directive to published declarations May 14, 2026
Copilot finished work on behalf of nev21 May 14, 2026 03:57
Comment thread lib/scripts/setTsReferences.js
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api-extractor.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • www.googleapis.com
    • Triggering command: /usr/local/bin/node node install.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of nev21 May 14, 2026 04:21
Copilot AI requested a review from nev21 May 14, 2026 04:21
nevware21-bot
nevware21-bot previously approved these changes May 14, 2026
Copy link
Copy Markdown
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread lib/scripts/setTsReferences.js Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Compilation Errors: ES2015 Built‑ins Required by nevware21 Type Definitions

4 participants