dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

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

Open johanrd opened this issue 2 years ago • 1 comments

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:

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?

johanrd avatar Jan 17 '24 20:01 johanrd

i believe you should export type from here https://github.com/iamkun/dayjs/blob/dev/types/plugin/isoWeek.d.ts#L6 reuse from here https://github.com/iamkun/dayjs/blob/dev/types/index.d.ts#L31 and finally add them here https://github.com/iamkun/dayjs/blob/dev/types/plugin/duration.d.ts#L21

btw https://github.com/iamkun/dayjs/issues/1354 was such a long time ago

zardoy avatar Jan 18 '24 14:01 zardoy