From 529b0790d6f08aaf2084f46123836439eb14eda0 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 21 Jul 2025 08:36:38 -0500 Subject: [PATCH] Improve type safety for getTrailId function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update function signature to accept id as string | number - Ensure consistent string conversion for all return paths - Add test coverage for numeric ID cases - Maintain backward compatibility with existing code This fixes potential type mismatches where marker IDs can be either strings or numbers throughout the codebase. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- assets/js/map_helpers.ts | 6 +++--- test/assets/js/map_helpers_test.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/assets/js/map_helpers.ts b/assets/js/map_helpers.ts index 1c690a0..caf1950 100644 --- a/assets/js/map_helpers.ts +++ b/assets/js/map_helpers.ts @@ -34,7 +34,7 @@ export function parseTimestamp(timestamp: string | number | Date | undefined): n /** * Get trail ID from marker data */ -export function getTrailId(data: { callsign_group?: string; callsign?: string; id: string }): string { +export function getTrailId(data: { callsign_group?: string; callsign?: string; id: string | number }): string { // Prioritize callsign_group and callsign over extracting from ID if (data.callsign_group) { return data.callsign_group; @@ -53,8 +53,8 @@ export function getTrailId(data: { callsign_group?: string; callsign?: string; i return withoutPrefix.replace(/_\d+$/, ""); } - // For regular IDs, return as-is - return data.id; + // For regular IDs, return as string + return String(data.id); } /** diff --git a/test/assets/js/map_helpers_test.ts b/test/assets/js/map_helpers_test.ts index 72e2a78..6181248 100644 --- a/test/assets/js/map_helpers_test.ts +++ b/test/assets/js/map_helpers_test.ts @@ -92,6 +92,20 @@ describe('map_helpers', () => { }; expect(getTrailId(data)).toBe('REALCALL'); }); + + test('handles numeric ID', () => { + const data = { + id: 12345 + }; + expect(getTrailId(data)).toBe('12345'); + }); + + test('handles numeric historical ID', () => { + const data = { + id: 'hist_MYCALL_12345' + }; + expect(getTrailId(data)).toBe('MYCALL'); + }); }); describe('saveMapState', () => {