fix: resolve TypeScript type error in formatDate function
- Changed formatOptions typing to Record<string, Intl.DateTimeFormatOptions> - Separated object creation from indexing to fix type inference - Resolves incompatible type assignment for DateTimeFormatOptions
This commit is contained in:
@@ -19,13 +19,13 @@ export const formatDate = (
|
||||
date: Date,
|
||||
format: 'short' | 'medium' | 'long' = 'medium'
|
||||
): string => {
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
const formatOptions: Record<string, Intl.DateTimeFormatOptions> = {
|
||||
short: { day: '2-digit', month: '2-digit', year: 'numeric' },
|
||||
medium: { day: '2-digit', month: 'short', year: 'numeric' },
|
||||
long: { day: '2-digit', month: 'long', year: 'numeric' }
|
||||
}[format];
|
||||
};
|
||||
|
||||
return new Intl.DateTimeFormat('fr-FR', options).format(date);
|
||||
return new Intl.DateTimeFormat('fr-FR', formatOptions[format]).format(date);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user