Overview
We have a module that exports objects from other files.
For simplicity sake, let's call this Vehicle. It exports Car, Boat, and Plane.
We have an enum that corresponds to these vehicles, let's say the following:
enum Vehicles {
Car,
Boat,
Plane,
}
We are looking to use the enum to specify which imported object we should then use.
Question
We're aware that we can do a switch/case, but this becomes unnecessarily long as our enum grows. Some of our classes export dozens of variations of objects that we then use elsewhere (we are unable to use types/interfaces to simplify).
switch(vehicle) {
case Vehicles.Car: {
return Car;
}
case Vehicles.Boat: {
return Boat;
}
case Vehicles.Plane: {
return Plane;
}
}
More info
We are using TypeScript with Svelte. The import is a package (e.g. Google Charts [charts], fortawesome [icons], etc.). We are looking to create a sort of wrapper to easily initialize specific components.
Example:
<script lang="ts">
import { a, b, c } from x
const y = () => {
// logic here
}
</script>
<y/>
This question seems to be TypeScript-specific, so I've purposely left out svelte tag from my question