iamkun / iamkun/dayjs

Argument of type `"quarter"` | `"isoWeek"` is not assignable to parameter of type 'DurationUnitType'

Open
#2,557 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**
Typescript complains that `"quarter"` and `"isoWeek"` are not assignable to parameter of type `DurationUnitType` when using the `isoWeek` and `quarterOfYear` in combination with `duration`:

```ts
import dayjs from 'dayjs'
import isoWeek from 'dayjs/plugin/isoWeek'
import duration from 'dayjs/plugin/duration'
import quarterOfYear from 'dayjs/plugin/quarterOfYear'

dayjs.extend(duration)
dayjs.extend(quarterOfYear)
dayjs.extend(isoWeek)

dayjs.duration(1, 'quarter') // Argument of type '"quarter"' is not assignable to parameter of type 'DurationUnitType | undefined' ts 2345
dayjs.duration(1, 'isoWeek') // Argument of type '"isoWeek"' is not assignable to parameter of type 'DurationUnitType | undefined' ts 2345
```

**Expected behavior**
Plugin `isoWeek` and `quarterOfYear` to extend the expected input types of `dayjs.duration()`

**Information**
- Day.js Version v1.11.10
- Typescript v5.3.3

Possibly related to #1354, @zardoy?

Contributor guide

Open the contributing guide

Research direction

Start by locating the type declarations for the duration, isoWeek, and quarterOfYear plugins, then reproduce the TypeScript example from the issue. Done means the example accepts both "quarter" and "isoWeek" as inputs to dayjs.duration().

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.