iamkun / dayjs

⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
https://day.js.org
MIT License
46.81k stars 2.29k forks source link

minMax return a unexpected value #1405

Open wsi18n opened 3 years ago

wsi18n commented 3 years ago

Describe the bug

dayjs.max('2021-01-01', dayjs('2020-01-01')) // => '2021-01-01'
dayjs.max('2020-01-01', dayjs('2021-01-01')) // => dayjs('2021-01-01')
dayjs.max(dayjs('2021-01-01'), '2020-01-01') // => TypeError: n[r].isValid is not a function

but in the minMax.d.ts :

declare module 'dayjs' {
  export function max(dayjs: Dayjs[]): Dayjs
  export function max(...dayjs: Dayjs[]): Dayjs
  export function min(dayjs: Dayjs[]): Dayjs
  export function min(...dayjs: Dayjs[]): Dayjs
}

Expected behavior

dayjs.max('2021-01-01', dayjs('2020-01-01')) // => dayjs('2021-01-01')
dayjs.max('2020-01-01', dayjs('2021-01-01')) // => dayjs('2021-01-01')
dayjs.max(dayjs('2021-01-01'), '2020-01-01') // => dayjs('2021-01-01')

or

dayjs.max('2021-01-01', dayjs('2020-01-01')) // => TypeError: '2021-01-01' is not a instance of Dayjs
dayjs.max('2020-01-01', dayjs('2021-01-01')) // => TypeError: '2021-01-01' is not a instance of Dayjs
dayjs.max(dayjs('2021-01-01'), '2020-01-01') // => TypeError  '2020-01-01' is not a instance of Dayjs

Information

iamkun commented 3 years ago

a reproduction demo, please?