From 50e1cf1f4d0700e2b1810ede7d597b7bfbaa2a56 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 14 May 2026 02:48:24 +0000
Subject: [PATCH 1/4] Initial plan
From df8ef6fee08bc455e51b3e5c8f3c2cc040fd9e69 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 14 May 2026 02:53:38 +0000
Subject: [PATCH 2/4] Add ES2015 lib to tsconfig files to fix compilation
errors
Agent-Logs-Url: https://github.com/nevware21/ts-utils/sessions/2aef322b-e961-4a68-9320-06e44706e006
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
---
lib/test/tsconfig.test.esnext.json | 1 +
lib/test/tsconfig.test.json | 1 +
lib/test/tsconfig.test.karma.json | 1 +
lib/test/tsconfig.worker.karma.json | 1 +
lib/tsconfig.base.json | 1 +
5 files changed, 5 insertions(+)
diff --git a/lib/test/tsconfig.test.esnext.json b/lib/test/tsconfig.test.esnext.json
index 4632df0c..cedf0d17 100644
--- a/lib/test/tsconfig.test.esnext.json
+++ b/lib/test/tsconfig.test.esnext.json
@@ -6,6 +6,7 @@
"module": "commonjs",
"moduleResolution": "node",
"target": "ESNext",
+ "lib": ["ESNext", "DOM"],
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noEmitHelpers": false,
diff --git a/lib/test/tsconfig.test.json b/lib/test/tsconfig.test.json
index b3cfd23b..e16e026c 100644
--- a/lib/test/tsconfig.test.json
+++ b/lib/test/tsconfig.test.json
@@ -6,6 +6,7 @@
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
+ "lib": ["ES2015", "DOM"],
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noEmitHelpers": false,
diff --git a/lib/test/tsconfig.test.karma.json b/lib/test/tsconfig.test.karma.json
index 5fe3f9d3..cf8aee52 100644
--- a/lib/test/tsconfig.test.karma.json
+++ b/lib/test/tsconfig.test.karma.json
@@ -6,6 +6,7 @@
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
+ "lib": ["ES2015", "DOM"],
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noEmitHelpers": false,
diff --git a/lib/test/tsconfig.worker.karma.json b/lib/test/tsconfig.worker.karma.json
index 1d7341c4..45be04d6 100644
--- a/lib/test/tsconfig.worker.karma.json
+++ b/lib/test/tsconfig.worker.karma.json
@@ -6,6 +6,7 @@
"module": "es6",
"moduleResolution": "node",
"target": "es5",
+ "lib": ["ES2015", "DOM"],
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noEmitHelpers": false,
diff --git a/lib/tsconfig.base.json b/lib/tsconfig.base.json
index 6f136691..c3a06441 100644
--- a/lib/tsconfig.base.json
+++ b/lib/tsconfig.base.json
@@ -6,6 +6,7 @@
"module": "es6",
"moduleResolution": "node",
"target": "es5",
+ "lib": ["ES2015", "DOM"],
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noEmitHelpers": false,
From 337e0e8df48008a30840b1d6d0168d211ff0ff15 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 14 May 2026 03:56:47 +0000
Subject: [PATCH 3/4] Add reference lib es2015 directive to published d.ts and
update CHANGELOG
Agent-Logs-Url: https://github.com/nevware21/ts-utils/sessions/241c832b-e34d-4648-abcd-efe1276dc2a1
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
---
CHANGELOG.md | 7 ++++++
lib/scripts/setTsReferences.js | 40 ++++++++++++++++++++++++++++++++++
lib/src/index.ts | 2 ++
lib/src/polyfills.ts | 2 ++
package.json | 2 +-
5 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 lib/scripts/setTsReferences.js
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cb5e852b..7e924f6d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,13 @@
## Changelog
+### Bug Fixes
+
+- [#565](https://github.com/nevware21/ts-utils/issues/565) Fixed compilation errors for consumers using ES5-only TypeScript lib settings.
+ - Added `/// ` directive to the published `.d.ts` declaration file so that consumers with `"lib": ["ES5", "DOM"]` (or no explicit `lib`) can compile without "Cannot find name 'Symbol'" / "Cannot find name 'Iterator'" errors.
+ - The fix includes a post-processing step (`lib/scripts/setTsReferences.js`) that adds the reference directive to the api-extractor bundled output, since api-extractor strips `/// ` from its rollup.
+ - Also added `"lib": ["ES2015", "DOM"]` to the library build and test tsconfig files for consistent compile-time validation.
+
### Features
- Added comprehensive encoding and decoding functions for multiple formats:
diff --git a/lib/scripts/setTsReferences.js b/lib/scripts/setTsReferences.js
new file mode 100644
index 00000000..3ca01a12
--- /dev/null
+++ b/lib/scripts/setTsReferences.js
@@ -0,0 +1,40 @@
+/*
+ * @nevware21/ts-utils
+ * https://github.com/nevware21/ts-utils
+ *
+ * Copyright (c) 2022-2026 NevWare21 Solutions LLC
+ * Licensed under the MIT license.
+ */
+
+"use strict";
+
+/**
+ * Post-processing script to add TypeScript lib reference directives to the bundled
+ * declaration file generated by api-extractor.
+ *
+ * The api-extractor tool strips `/// ` directives from the
+ * bundled output. These directives are required so that consumers using ES5-only lib
+ * settings in their tsconfig (e.g. `"lib": ["ES5", "DOM"]`) can compile code that
+ * references the package's type declarations without encountering "Cannot find name"
+ * errors for ES2015 built-ins such as Symbol, Iterator, Iterable, etc.
+ */
+
+var fs = require("fs");
+var path = require("path");
+
+var bundledDtsFile = path.resolve(__dirname, "../dist/types/ts-utils.d.ts");
+var referenceDirective = "/// ";
+
+if (!fs.existsSync(bundledDtsFile)) {
+ console.error("ERROR: Bundled d.ts file not found: " + bundledDtsFile);
+ process.exit(1);
+}
+
+var content = fs.readFileSync(bundledDtsFile, "utf8");
+
+if (content.indexOf(referenceDirective) === -1) {
+ fs.writeFileSync(bundledDtsFile, referenceDirective + "\n" + content, "utf8");
+ console.log("Added '" + referenceDirective + "' to " + path.relative(process.cwd(), bundledDtsFile));
+} else {
+ console.log("Reference directive already present in " + path.relative(process.cwd(), bundledDtsFile));
+}
diff --git a/lib/src/index.ts b/lib/src/index.ts
index d0d590b2..df31fd6f 100644
--- a/lib/src/index.ts
+++ b/lib/src/index.ts
@@ -6,6 +6,8 @@
* Licensed under the MIT license.
*/
+///
+
export { arrAppend } from "./array/append";
export { ArrPredicateCallbackFn, ArrPredicateCallbackFn2, ArrMapCallbackFn, ArrFlatMapCallbackFn, ArrFromMapFn } from "./array/callbacks";
export { arrAt } from "./array/at";
diff --git a/lib/src/polyfills.ts b/lib/src/polyfills.ts
index 58910c92..6f1854e1 100644
--- a/lib/src/polyfills.ts
+++ b/lib/src/polyfills.ts
@@ -6,6 +6,8 @@
* Licensed under the MIT license.
*/
+///
+
import { arrForEach } from "./array/forEach";
import { ArrCls, ArrProto, ObjClass, StrProto } from "./internal/constants";
import { polyIsArray, polyArrIncludes, polyArrFind, polyArrFindIndex, polyArrFindLastIndex, polyArrFindLast, polyArrFrom } from "./polyfills/array";
diff --git a/package.json b/package.json
index c9c440d3..9c6f8b0b 100644
--- a/package.json
+++ b/package.json
@@ -185,7 +185,7 @@
"prep-release": "npm run cleanBuild && npm run npm-pack",
"npm-pack": "copyfiles README.md LICENSE lib && cd lib && npm pack",
"npm-publish": "publish-npm",
- "dtsgen": "api-extractor run --local --verbose",
+ "dtsgen": "api-extractor run --local --verbose && node lib/scripts/setTsReferences.js",
"size": "size-limit",
"size-save": "size-limit --clean-dir --save-bundle build/size",
"size-check": "node lib/test/bundle-size-check.js",
From 287c358e13f2c20ef2c7c9235d02eaa01ba3495f Mon Sep 17 00:00:00 2001
From: nev21 <82737406+nev21@users.noreply.github.com>
Date: Wed, 13 May 2026 22:34:00 -0700
Subject: [PATCH 4/4] Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
---
lib/scripts/setTsReferences.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/scripts/setTsReferences.js b/lib/scripts/setTsReferences.js
index 3ca01a12..03d7a62a 100644
--- a/lib/scripts/setTsReferences.js
+++ b/lib/scripts/setTsReferences.js
@@ -31,9 +31,10 @@ if (!fs.existsSync(bundledDtsFile)) {
}
var content = fs.readFileSync(bundledDtsFile, "utf8");
+var newLine = content.indexOf("\r\n") !== -1 ? "\r\n" : "\n";
if (content.indexOf(referenceDirective) === -1) {
- fs.writeFileSync(bundledDtsFile, referenceDirective + "\n" + content, "utf8");
+ fs.writeFileSync(bundledDtsFile, referenceDirective + newLine + content, "utf8");
console.log("Added '" + referenceDirective + "' to " + path.relative(process.cwd(), bundledDtsFile));
} else {
console.log("Reference directive already present in " + path.relative(process.cwd(), bundledDtsFile));