I have a function in Typescript export const getFormatedDate = ( timestamp: number…
- User
I have a function in Typescript export const getFormatedDate = ( timestamp: number | string, { todayFormat, yesterdayFormat, defaultFormat }: IFormats = {}, returnValue ): string | null => { if (!timestamp) return returnValue; const date = dayjs(timestamp).tz('Europe/Moscow'); if (date.isToday() && Boolean(todayFormat)) { return date.format(todayFormat); } if (date.isYesterday() && Boolean(yesterdayFormat)) { return date.format(yesterdayFormat); } if (typeof defaultFormat === 'string') { return date.format(defaultFormat); } return date.format(DATE_FORMAT_MESSAGE_WITHOUT_YEAR); }; I want returnValue paratemeted to be equal to null as a default and also want the type for it to be null | string. fix the code
- Assistant
export const getFormatedDate = ( timestamp: number | string, { todayFormat, yesterdayFormat, defaultFormat }: IFormats = {}, returnValue: string | null = null ): string | null => { if (!timestamp) return returnValue; const date = dayjs(timestamp).tz('Europe/Moscow'); if (date.isToday() && Boolean(todayFormat)) { return date.format(todayFormat); } if (date.isYesterday() && Boolean(yesterdayFormat)) { return date.format(yesterdayFormat); } if (typeof defaultFormat === 'string') { return date.format(defaultFormat); } return date.format(DATE_FORMAT_MESSAGE_WITHOUT_YEAR); };