Symptom
Calling formatDate(workout.completedAt) throws "date.toLocaleDateString is not a function" or returns unexpected results like "Invalid Date". The completedAt field is typed as Date but behaves like a string at runtime.
Expected
completedAt should be a real Date object so that date formatting methods work correctly.
What you know
The API client fetches workout data from a REST API. The TypeScript type says completedAt: Date, but JSON responses always contain strings. The API client casts the response with as WorkoutData[] without converting date fields.
Hints
TypeScript
TypeScript ready
Test Output
▶
Click "Run Tests" to execute your code