Struggling with formatting time in a web component using TypeScript and React. The code below is working:
new Date(myDate)
.toLocaleTimeString(
'en-US',
{ weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour12: false });
Trying to reuse the format option on multiple locations, but encountering an issue with this code:
const timeformat = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour12: false };
new Date(status.start).toLocaleTimeString('en-US',timeformat);
TypeScript error message:
Argument of type '{ weekday: string; year: string; month: string; day: string; hour12: boolean; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
Types of property 'weekday' are incompatible.
Type 'string' is not assignable to type '"short" | "long" | "narrow" | undefined'. TS2345
Tried:
const timeFormat : DateTimeFormatOptions = {...}
Unable to find the type. Any help would be appreciated!
Thank you!