I want to create a type match when calling a method with enum values.
Imagine the next example:
enum Vehicle {
Car,
Bus,
Plane
};
type CarParams = { carId: string };
type BusParams = { busId: string };
type PlaneParams = { planeId: string };
const TypeMap = {
[Vehicle.Car]: CarParams,
[Vehicle.Bus]: BusParams,
[Vehicle.Plane]: PlaneParams,
};
function showDriver(vehicle: Vehicle, params: TypeMap[valueof vehicle]): void {
// ...
}
I can't really do this: TypeMap[valueof vehicle]
But I want to help whoever uses my method to understand the parameters they need to send, so that calls look like this:
showDriver(Vehicle.Bus, { busI...
This would automatically autocomplete to busId and expect a string.
How do I do that?