Skip to content
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: use Map instead of Record for train summaries/projections #10808

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

emersion
Copy link
Member

TypeScript implicitly converts Record keys to strings. Map is safer.

TypeScript implicitly converts Record keys to strings. Map is safer.

Signed-off-by: Simon Ser <[email protected]>
@emersion emersion requested a review from a team as a code owner February 14, 2025 09:35
@github-actions github-actions bot added the area:front Work on Standard OSRD Interface modules label Feb 14, 2025
Copy link
Contributor

@SharglutDev SharglutDev left a comment

Choose a reason for hiding this comment

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

Thanks !

@anisometropie
Copy link
Contributor

I’m not against using map here, but Why is it safer ?

The record is using TrainScheduleId = string & { readonly __type: unique symbol } as key, so there is no way to put anything else but a TrainScheduleId string as the key. We never coerced number into string in there.

@emersion
Copy link
Member Author

emersion commented Feb 14, 2025

See the discussion and TypeScript playground link here: #10679 (comment)

tl;dr Record is a footgun when the key isn't a plain string :o

@anisometropie
Copy link
Contributor

See the discussion and TypeScript playground link here: #10679 (comment)

tl;dr Record is a footgun when the key isn't a plain string :o

Nice

@emersion emersion added this pull request to the merge queue Feb 18, 2025
Merged via the queue into dev with commit f4e0c84 Feb 18, 2025
27 checks passed
@emersion emersion deleted the emr/train-id-map branch February 18, 2025 08:58
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants