iamkun / iamkun/dayjs

minMax return a unexpected value

Open
#1,405 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**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**
- Day.js Version [e.g. v1.0.0]
- OS: any
- Browser: any
- Time zone: any

Contributor guide

Open the contributing guide

Research direction

Start at the dayjs.max/minMax entry point and inspect the minMax.d.ts declarations mentioned in the issue. Reproduce the three mixed string and Dayjs calls, then clarify whether mixed inputs should be accepted or rejected before aligning the behavior and declarations and adding coverage for the chosen contract.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.