-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
front: add type-safe APIs for durations and distances #8816
Labels
area:front
Work on Standard OSRD Interface modules
kind:enhancement
Improvement of existing features
Comments
emersion
added a commit
that referenced
this issue
Dec 3, 2024
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Dec 13, 2024
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Dec 23, 2024
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Dec 23, 2024
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Jan 3, 2025
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Jan 3, 2025
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Jan 3, 2025
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Jan 3, 2025
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Jan 10, 2025
Signed-off-by: Simon Ser <[email protected]> References: #8816
emersion
added a commit
that referenced
this issue
Jan 10, 2025
Signed-off-by: Simon Ser <[email protected]> References: #8816
github-merge-queue bot
pushed a commit
that referenced
this issue
Jan 13, 2025
Signed-off-by: Simon Ser <[email protected]> References: #8816
The Ref #10230 (comment) |
This was referenced Jan 20, 2025
11 tasks
7 tasks
Still TODO in this issue: introduce a type for distances. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area:front
Work on Standard OSRD Interface modules
kind:enhancement
Improvement of existing features
Description and goal
We're planning to use
Date
instead of ad-hoc strings/numbers for timestamps for improved type safety. We don't have an equivalent dedicated type for durations and distances.Upside of using a dedicated type is that mixups are prevented. Typically when doing math on duration/distance values, it can be easy to mix millimeters and kilometers, or millimeters and a number of elements. A dedicated type would make the TypeScript compiler complain about such mistakes.
Possible solution 1: TypeScript subtypes
See https://timjohns.ca/typescripts-hidden-feature-subtypes.html
Downside: math on distances doesn't work, it returns a bare number.
To fix, we'd need to define helper functions such as:
But it's quite tempting for users to just litter casts everywhere and loose the type safety benefits.
Possible solution 2: dedicated class
Introduce dedicated classes for durations and distances.
Similar to the upcoming temporal standard: https://tc39.es/proposal-temporal/docs/duration.html
Downside: math operators don't work (+, -, etc), need to use the dedicated methods. But that's similar to
Date
here.valueOf
is possibly too tempting for users to perform math operations, so maybe should leave it out.Acceptance criteria
.
The text was updated successfully, but these errors were encountered: