Improve type safety for getTrailId function
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
746db1a4c2
commit
529b0790d6
2 changed files with 17 additions and 3 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue