Skip to content

refactor(typescript): introduce the Constructor<T> utility type - #1011

Merged
tbouffard merged 2 commits into
mainfrom
refactor/introduce_type_Constructor
Feb 23, 2026
Merged

refactor(typescript): introduce the Constructor<T> utility type#1011
tbouffard merged 2 commits into
mainfrom
refactor/introduce_type_Constructor

Conversation

@tbouffard

@tbouffard tbouffard commented Feb 23, 2026

Copy link
Copy Markdown
Member

Add a generic Constructor type in types.ts to simplify and reuse constructor type declarations:

  • Replace the inline constructor type in ShapeConstructor with Constructor
  • Use ShapeConstructor in EdgeHandler to replace the ad-hoc cast

Summary by CodeRabbit

  • Refactor
    • Improved internal type declarations and reuse to make the codebase safer and more maintainable. No changes to user-facing behavior or functionality.

Add a generic Constructor<T> type in types.ts to simplify and reuse constructor type declarations:
- Replace the inline constructor type in ShapeConstructor with Constructor<Shape>
- Use ShapeConstructor in EdgeHandler to replace the ad-hoc cast
@tbouffard tbouffard added the refactor Code refactoring label Feb 23, 2026
@coderabbitai

coderabbitai Bot commented Feb 23, 2026

Copy link
Copy Markdown

Walkthrough

Adds a reusable generic Constructor<T> type and refactors ShapeConstructor to use it; updates EdgeHandler.ts to import/use the refactored type. Changes are type-level only with no runtime behavior modifications.

Changes

Cohort / File(s) Summary
Type Definitions
packages/core/src/types.ts
Adds export type Constructor<T> = new (...args: any[]) => T; and changes ShapeConstructor to Constructor<Shape> (replaces prior inline constructor type).
Type Usage
packages/core/src/view/handler/EdgeHandler.ts
Replaces a direct constructor type cast with the exported ShapeConstructor type import to improve type consistency; no runtime logic changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks required sections from the template: PR Checklist, issue reference, testing information, and screenshots/documentation details. Complete the PR description by including the PR Checklist, referencing the issue number, confirming tests added, and explaining why screenshots are not applicable if needed.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing a generic Constructor utility type and refactoring existing code to use it.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/types.ts (1)

1464-1473: Consider adding a brief description to the Constructor<T> JSDoc.

Other significant utility types in this file (PerimeterFunction, EdgeStyleFunction, MarkerFactoryFunction) carry prose descriptions. Adding one here would keep documentation consistent for consumers of the public API.

✏️ Suggested improvement
 /**
+ * Represents a constructor function for a class that produces instances of type `T`.
+ *
  * `@since` 0.23.0
  */
 export type Constructor<T> = new (...args: any[]) => T;

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66c1d02 and bed88e0.

📒 Files selected for processing (2)
  • packages/core/src/types.ts
  • packages/core/src/view/handler/EdgeHandler.ts

Comment thread packages/core/src/types.ts
Comment thread packages/core/src/types.ts
improve jsdoc [skip ci]
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/types.ts (1)

1464-1468: Optional: add @category to Constructor<T> for documentation discoverability.

All domain-relevant exported types carry a @category tag. Constructor<T> is a general utility type, but if it appears in the generated API docs it should be discoverable. Consider @category Shape (to mirror ShapeConstructor) or a new @category Utility.


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bed88e0 and 174ead0.

📒 Files selected for processing (1)
  • packages/core/src/types.ts

@tbouffard
tbouffard merged commit c4659cb into main Feb 23, 2026
6 checks passed
@tbouffard
tbouffard deleted the refactor/introduce_type_Constructor branch February 23, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant