parkCar function fails to update carSpotMap, causing unparkCar to fail : Typescript
Author: ShashankAlampallyCreated Jan 21, 2026Updated Jan 21, 2026
Describe the bug
In ParkingLot.ts, the parkCar function successfully parks the vehicle in the Spot object but fails to save the mapping in this.carSpotMap.(Typescript)
To Reproduce
- Create a ParkingLot instance.
- Park a car using
lot.parkCar(vehicle). - Try to unpark the same car using
lot.unparkCar(vehicle).
Expected behavior The car should be unparked successfully.
Actual behavior The system throws an Error: "Car is not Parked" because the map lookup returns undefined.
Suggested Fix
Add this line in ParkingLot.ts inside the parkCar method:
this.carSpotMap[vehicle.getNumber()] = availableSpot;
Source: ashishps1/awesome-low-level-design