I am looking to pass either a single enum value or an array of enum values to a function. In order to achieve this, I have created a custom function:
export enum SettingType {
hairColors ='haircolors',
hatSizes = 'hatsizes'
}
public getSettings(settingTypes: SettingType | SettingType[]) {
if (settingType instanceOf SettingType) {
//Fetch data for one setting type
} else {
//Fetch data for all settings types
}
}
public theUsage() {
getSettings(SettingType.hairColors);
getSettings([ SettingType.hairColors, SettingType.hatSizes ]);
}
The function theUsage demonstrates how I intend to utilize the getSettings method. I aim to pass either a single setting type or multiple setting types. The getSettings function will then handle the data retrieval based on the provided input.
However, during implementation, I encounter an error message indicating:
The right-hand side of an 'instanceof' expression must be of type 'any'
or of a type assignable to the 'Function' interface type.
I am seeking a solution to determine whether settingTypes contains a single enum value or an array of enum values. How can I properly check for this distinction?