I have a requirement for enabling type checking on a specific class
Here is the relevant code snippet:
class FlightFilter implements Filter {
get filters() {
return {
departTime: { name: 'Departure Time', type: FilterTypes.Range },
price: { name: 'Price Range', type: FilterTypes.Range },
flightType: { name: 'Flight Type', type: FilterTypes.CheckboxList },
flightClass: { name: 'Flight Class', type: FilterTypes.CheckboxList },
airline: { name: 'Airline', type: FilterTypes.CheckboxList },
airports: { name: 'Airports', type: FilterTypes.CheckboxList }
};
}
fillData() {
for (const filter of this.filters) {
console.log(filter);
}
}
// Other methods and properties implementations...
}
I attempted to create an interface for it but I am unsure how to handle multiple instances of a property with dynamic names
Similar to this concept:
interface Filter {
filters(): Object;
fillData(): void;
// This is where I want to have multiple instances
[name: String](ticket: Object): Boolean;
[name: String]DataGenerator(): void;
[name: String]Model: any
}
Please note that the above code is extracted from my JavaScript project and I am looking to transition to TypeScript