Skip to content

style(Typing): Use stronger types#2714

Merged
jbocce merged 6 commits into
cornerstonejs:mainfrom
paulglx:chore/stronger-types
May 12, 2026
Merged

style(Typing): Use stronger types#2714
jbocce merged 6 commits into
cornerstonejs:mainfrom
paulglx:chore/stronger-types

Conversation

@paulglx
Copy link
Copy Markdown
Contributor

@paulglx paulglx commented Apr 27, 2026

Context

This PR adds stronger types at three locations in the codebase :

  • BaseVolumeViewport.ts
  • Synchronizer.ts
  • ISynchronizerEventHandler.ts

This enhancement comes from issues in our codebase using Cornerstone3D, where some typing quirks cause us to re-annotate some objects as the proper type.

Changes & Results

  • Added stronger type annotations

Testing

  • Linter passes
  • The tests pass.

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • "OS:
  • "Node version:
  • "Browser:

@paulglx paulglx force-pushed the chore/stronger-types branch 2 times, most recently from 91fbe52 to 646f865 Compare April 28, 2026 14:38
@jbocce jbocce self-requested a review May 11, 2026 14:25
@jbocce
Copy link
Copy Markdown
Collaborator

jbocce commented May 11, 2026

@claude review

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, comment @claude review on this pull request to trigger a review.

Copy link
Copy Markdown
Collaborator

@wayfarer3130 wayfarer3130 left a comment

Choose a reason for hiding this comment

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

I'm ok with the type improvements.
@jbocce - why don't you take a look as well, but I think it is generally in the right direction.

}
const preset: ViewportPreset | undefined =
typeof presetNameOrObj === 'string'
? VIEWPORT_PRESETS.find((p) => p.name === presetNameOrObj)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's use vpPreset or viewportPreset instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Pardon me, I meant the p should be renamed. So as is this case now please rename p to preset.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the confusion! I amended the commit

@paulglx paulglx force-pushed the chore/stronger-types branch from 986b213 to 2cd5352 Compare May 12, 2026 12:25
public getProperties = (volumeId?: string): VolumeViewportProperties => {
public getProperties = (
volumeId?: string
): VolumeViewportProperties | undefined | null => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't return null in this funtion I don't think, so remove the | null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It does return null lines 1326-1328 :

    const volume = cache.getVolume(volumeId);

    if (!volume) {
      return null;
    }

It's the only occurence, we could make it more cohesive by returning undefined instead (bare return;)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry about that. Let's leave it as you have it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No worries, please tell me if you require any other change!


function volumeNewImageHandler(cameraEvent) {
function volumeNewImageHandler(
cameraEvent: EventTypes.CameraModifiedEvent
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not use cameraEvent:Event instead and just narrow once on line 207? I think I prefer that over three casts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I amended the commit

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please do not change history by doing either an amend or rebase or anything else during PR. We prefer to see the exact sequence of commits and when they are done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, next time I'll do it sequentially!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you.

@paulglx paulglx force-pushed the chore/stronger-types branch from 2cd5352 to 676847a Compare May 12, 2026 13:11
Copy link
Copy Markdown
Collaborator

@jbocce jbocce left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for this change.

@jbocce jbocce merged commit 06a58b1 into cornerstonejs:main May 12, 2026
11 checks passed
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.

3 participants