iamkun / dayjs

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

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

Open johanrd opened 10 months ago

johanrd commented 10 months ago

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

zardoy commented 10 months ago

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