Repository navigation
v8.4.1
Changes
- fix(file-size): 🐛 Type FileSize add and subtract as FileSize
Release details
- npm: https://www.npmjs.com/package/@haskou/value-objects/v/8.4.1
- Pull request: #99
- Source branch:
fix/file-size-arithmetic-types - Version bump:
patch
Pull request notes
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
FileSizeis a closed operation, so the return type is exact.NumberValueObjectis unchanged: its arithmetic can fail on subclass invariants, sothiswould be a wrong promise there. - Implemented with
clone(), so subclasses ofFileSizekeep their own type at runtime. - Breaking at type level:
size.add(100)with a plain number no longer compiles. Passnew FileSize(100). - Docs for
FileSizeupdated 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.