Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export type of duration plugin #1094

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 37 additions & 34 deletions types/plugin/duration.d.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export default plugin
export as namespace plugin;
export = plugin

type DurationInputType = string | number | object
type DurationAddType = number | object | Duration
declare namespace plugin {
type DurationInputType = string | number | object
type DurationAddType = number | object | Duration

export declare class Duration {
constructor (input: DurationInputType, unit?: string, locale?: string)
interface Duration {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small question, can we still use class Duration here, or is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred when using a class in a namespace, so the class was implemented as an interface.
It probably conflicts with the const plugin object. https://stackoverflow.com/a/51716899

new (input: DurationInputType, unit?: string, locale?: string): Duration

clone(): Duration

humanize(withSuffix?: boolean): string
clone(): Duration

milliseconds(): number
asMilliseconds(): number
humanize(withSuffix?: boolean): string

seconds(): number
asSeconds(): number
milliseconds(): number
asMilliseconds(): number

minutes(): number
asMinutes(): number
seconds(): number
asSeconds(): number

hours(): number
asHours(): number
minutes(): number
asMinutes(): number

days(): number
asDays(): number
hours(): number
asHours(): number

weeks(): number
asWeeks(): number
days(): number
asDays(): number

months(): number
asMonths(): number
weeks(): number
asWeeks(): number

years(): number
asYears(): number
months(): number
asMonths(): number

as(unit: string): number
years(): number
asYears(): number

get(unit: string): number
as(unit: string): number

add(input: DurationAddType, unit? : string): Duration

subtract(input: DurationAddType, unit? : string): Duration
get(unit: string): number

toJSON(): string
add(input: DurationAddType, unit? : string): Duration

toISOString(): string
subtract(input: DurationAddType, unit? : string): Duration

locale(locale: string): Duration
toJSON(): string

toISOString(): string

locale(locale: string): Duration
}
}

declare module 'dayjs' {
export function duration(input?: DurationInputType , unit?: string): Duration
export function isDuration(d: any): d is Duration
export function duration(input?: plugin.DurationInputType , unit?: string): plugin.Duration
export function isDuration(d: any): d is plugin.Duration
}