Skip to content

fix(file-size): 🐛 Type FileSize add and subtract as FileSize - #99

Merged
haskou merged 1 commit into
masterfrom
fix/file-size-arithmetic-types
Oct 13, 2026
Merged

haskou merged 1 commit into
masterfrom
fix/file-size-arithmetic-types

Conversation

@haskou

@haskou haskou commented Oct 13, 2026

Copy link
Copy Markdown
Owner

What

FileSize.add and FileSize.subtract were typed as NumberValueObject (inherited), although at runtime they return a FileSize. They are now declared as add(other: FileSize): FileSize and subtract(other: FileSize): FileSize.

Notes

  • Adding or subtracting two FileSize is a closed operation, so the return type is exact. NumberValueObject is unchanged: its arithmetic can fail on subclass invariants, so this would be a wrong promise there.
  • Implemented with clone(), so subclasses of FileSize keep their own type at runtime.
  • Breaking at type level: size.add(100) with a plain number no longer compiles. Pass new FileSize(100).
  • Docs for FileSize updated with the new signatures and the negative-result error.

Verification

yarn test, yarn build pass. Coverage stays at 100%. The arithmetic test calls FileSize.to() on the results, so it only compiles if both return FileSize.

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@haskou
haskou merged commit e01029d into master Oct 13, 2026
3 checks passed
@haskou
haskou deleted the fix/file-size-arithmetic-types branch October 13, 2026 08:18
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.

1 participant