I have been trying to store a specific DateTimeFormatOptions
for the date.toLocaleString()
function so that I can easily use it in various parts of my application. Here is how I defined it:
export const timeFormat = { month: 'numeric', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false, timeZoneName: 'short', timeZone: 'UTC'}
However, when I attempt to use it, I receive the following error:
Argument of type '{ month: string; day: string; hour: string; minute: string; hour12: boolean; timeZoneName: string; timeZone: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
Types of property 'month' are incompatible.
Type 'string' is not assignable to type '"numeric" | "2-digit" | "short" | "long" | "narrow" | undefined'.
I have struggled with importing DateTimeFormatOptions and as a workaround, I have created a helper method to format the date. However, I may still need to import it in case users want to change their date preferences.