Skip to content

fix(types): Repair generate-types after Cluster export removal#187

Merged
RobinBol merged 1 commit into
masterfrom
fix/generate-types-cluster-import
May 19, 2026
Merged

fix(types): Repair generate-types after Cluster export removal#187
RobinBol merged 1 commit into
masterfrom
fix/generate-types-cluster-import

Conversation

@RobinBol
Copy link
Copy Markdown
Collaborator

The Generate TypeScript Types workflow has been failing on master since #181 merged (failing run).

Root cause

Two recently-merged PRs interact badly:

  • Fix named exports when used #182 (b799858) removed Cluster from lib/clusters/index.js exports because the base class doesn't belong in a file dedicated to named cluster exports.
  • Export types #181 added scripts/generate-types.mts, which on line 83 reaches the shared registry via:
    const clusterClass = clustersModule.default.Cluster.clusters[definition.ID];

Both PRs were green on their own branches because they didn't yet see each other's state. After the #181 merge, clustersModule.default.Cluster is undefined -> TypeError: Cannot read properties of undefined (reading 'clusters').

Fix

Cluster.clusters is a singleton static registry attached to the class itself; the path you reach the class through doesn't matter. The script already imports the top-level package entry as topModule for topModule.ZCLDataTypes, and index.js still exports Cluster, so the lookup just needs to go through there:

-    const clusterClass = clustersModule.default.Cluster.clusters[definition.ID];
+    const clusterClass = topModule.Cluster.clusters[definition.ID];

This avoids re-introducing the export PR #182 deliberately removed.

Drive-by template fix

While regenerating index.d.ts locally to verify, noticed the script's output didn't match the committed file: commit 05332d1 ("feat(types): add type definition for BoundCluster") added the BoundClusterInterface utility type directly to index.d.ts but forgot to add it to scripts/template.d.ts.txt. Without backporting it, the next workflow-driven regeneration would silently drop that public type. Added it to the template so the generated output stays stable.

Verification

On Node 24 locally:

Check Result
npm run generate-types success
npx tsc --noEmit index.d.ts clean
Regenerated index.d.ts vs committed no drift
npm run lint pass
npm test 76/76 pass

Once this lands, the Generate TypeScript Types workflow should go green on master and the auto-commit step becomes a no-op (since the template now reflects the committed index.d.ts).

The Generate TypeScript Types workflow has been failing on master since
PR #181 merged because two recent PRs collided:

- PR #182 (b799858) removed `Cluster` from `lib/clusters/index.js`
  exports, on the rationale that the base class doesn't belong in a
  file dedicated to named cluster exports.
- PR #181 introduced `scripts/generate-types.mts`, which looked up the
  shared `Cluster.clusters` static registry via
  `clustersModule.default.Cluster.clusters[ID]`.

After both landed, `clustersModule.default.Cluster` is `undefined` and
the script crashes. `Cluster.clusters` is a singleton attached to the
class itself, so reaching it through the top-level `index.js` entry
(already imported as `topModule`) yields the same registry without
re-introducing the removed re-export.

Also backports a `BoundClusterInterface` type to the generator template
that PR 05332d1 added directly to the generated `index.d.ts` but
forgot to add to the template. Without this, the next regeneration
would silently drop a public type from the package's type surface.

Verified locally on Node 24:
- `npm run generate-types` succeeds
- `npx tsc --noEmit index.d.ts` is clean
- Regenerated `index.d.ts` matches the committed file (no drift)
- `npm run lint` and `npm test` pass
@RobinBol RobinBol self-assigned this May 19, 2026
@RobinBol RobinBol requested a review from Copilot May 19, 2026 08:53
@RobinBol RobinBol marked this pull request as ready for review May 19, 2026 08:53
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

Fixes the TypeScript type-generation script after Cluster stopped being re-exported from lib/clusters/index.js, restoring the “Generate TypeScript Types” workflow on master. Also aligns the declaration template with the committed index.d.ts so future regenerations don’t drop the public BoundClusterInterface type.

Changes:

  • Update scripts/generate-types.mts to access the Cluster.clusters registry via the top-level index.js export (topModule.Cluster) instead of lib/clusters/index.js.
  • Add the missing BoundClusterInterface type to scripts/template.d.ts.txt to prevent drift on regeneration.

Reviewed changes

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

File Description
scripts/generate-types.mts Fixes the registry lookup path so type generation no longer crashes when Cluster isn’t exported from lib/clusters/index.js.
scripts/template.d.ts.txt Adds BoundClusterInterface to the template to keep generated index.d.ts stable across runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/template.d.ts.txt
@RobinBol RobinBol merged commit 4903d3f into master May 19, 2026
6 checks passed
@RobinBol RobinBol deleted the fix/generate-types-cluster-import branch May 19, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants