Skip to content

1.10.4 broke duration creation type in typescript #1354

Closed
@chengB12

Description

@chengB12

Describe the bug
In your own documentation: https://day.js.org/docs/en/durations/add

var a = dayjs.duration(1, 'd');
var b = dayjs.duration(2, 'd');

a.add(b).days(); // 3

it shows:

No overload matches this call.
  Overload 1 of 3, '(units: Partial<{ milliseconds: number; seconds: number; minutes: number; hours: number; days: number; months: number; years: number; weeks: number; }>): Duration', gave the following error.
    Argument of type 'Duration' is not assignable to parameter of type 'Partial<{ milliseconds: number; seconds: number; minutes: number; hours: number; days: number; months: number; years: number; weeks: number; }>'.
      Types of property 'milliseconds' are incompatible.
        Type '() => number' is not assignable to type 'number'.
  Overload 2 of 3, '(time: number, unit?: DurationUnitType | undefined): Duration', gave the following error.
    Argument of type 'Duration' is not assignable to parameter of type 'number'.
  Overload 3 of 3, '(ISO_8601: string): Duration', gave the following error.
    Argument of type 'Duration' is not assignable to parameter of type 'string'.ts(2769)

Expected behavior
No typescript type mismatch failure

Information

  • Day.js Version [e.g. v1.10.4]
  • OS: [windows]
  • Browser node 14.15.0
  • Time zone: not applicable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions