I created a function that takes in two parameters: data and format. I am attempting to define an ENUM(FormatOptions) for the "format" parameter. However, I encountered the following error:
Argument of type '"HH:MM"' is not compatible with parameter of type 'FormatOptions'
How can I correctly define the ENUM for the second argument? Check out the TypeScript Playground Here
Code:
const basicTime: any = {
year: 'numeric',
month: 'short',
day: '2-digit',
hour: 'numeric',
minute: 'numeric',
};
const hoursMinutes: any = {
hour: 'numeric',
minute: 'numeric',
};
enum FormatOptions {
HoursMinutes = 'HH:MM',
MonthDayYear = 'MM/DD/YYYY',
};
const dateFormat = (date: Date, format: FormatOptions) => {
if (format === 'HH:MM') {
return new Date(date).toLocaleString('en-US', hoursMinutes);
}
return new Date(date).toLocaleString('en-US', basicTime);
};
dateFormat(new Date, 'HH:MM');