Skip to content

Commit

Permalink
Fix typings to correctly reflect the usage
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiz4262 committed Jan 27, 2019
1 parent c4517a8 commit 123c72d
Showing 1 changed file with 72 additions and 92 deletions.
164 changes: 72 additions & 92 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,77 @@
export = dayjs;
export default dayjs

declare function dayjs (config?: dayjs.ConfigType, option?: dayjs.OptionType): dayjs.Dayjs
declare const dayjs: dayjsFn

declare namespace dayjs {
export type ConfigType = string | number | Date | Dayjs

export type OptionType = { locale: string }

export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'

interface DayjsObject {
years: number
months: number
date: number
hours: number
minutes: number
seconds: number
milliseconds: number
}

class Dayjs {
constructor (config?: ConfigType)

clone(): Dayjs

isValid(): boolean

year(): number

month(): number

date(): number

day(): number

hour(): number

minute(): number

second(): number

millisecond(): number

set(unit: UnitType, value: number): Dayjs

add(value: number, unit: UnitType): Dayjs

subtract(value: number, unit: UnitType): Dayjs

startOf(unit: UnitType): Dayjs

endOf(unit: UnitType): Dayjs

format(template?: string): string

diff(dayjs: Dayjs, unit: UnitType, float?: boolean): number

valueOf(): number

unix(): number

daysInMonth(): number

toDate(): Date

toArray(): number[]

toJSON(): string

toISOString(): string

toObject(): DayjsObject

toString(): string

isBefore(dayjs: Dayjs, unit?: UnitType): boolean

isSame(dayjs: Dayjs, unit?: UnitType): boolean

isAfter(dayjs: Dayjs, unit?: UnitType): boolean

isLeapYear(): boolean

locale(arg1: any, arg2?: any): Dayjs
}

export type PluginFunc = (option: ConfigType, d1: Dayjs, d2: Dayjs) => void

export function extend(plugin: PluginFunc, option?: ConfigType): Dayjs
type dayjsFn = {
(config?: ConfigType, option?: OptionType): DayjsInstance
extend(plugin: PluginFunc, option?: ConfigType): DayjsInstance
locale(arg1: any, arg2?: any): string
isDayjs(d: any): d is DayjsInstance
unix(t: number): DayjsInstance
}

export function locale(arg1: any, arg2?: any): string
export type ConfigType = string | number | Date | DayjsInstance

export type OptionType = { locale: string }

export type UnitType =
| 'millisecond'
| 'second'
| 'minute'
| 'hour'
| 'day'
| 'week'
| 'month'
| 'quarter'
| 'year'
| 'date'

export type PluginFunc = (
option: ConfigType,
d1: DayjsInstance,
d2: DayjsInstance
) => void

export type DayjsPlainObject = {
years: number
months: number
date: number
hours: number
minutes: number
seconds: number
milliseconds: number
}

export function isDayjs(d: any): d is Dayjs

export function unix(t: number): Dayjs
export type DayjsInstance = {
clone(): DayjsInstance
isValid(): boolean
year(): number
month(): number
date(): number
day(): number
hour(): number
minute(): number
second(): number
millisecond(): number
set(unit: UnitType, value: number): DayjsInstance
add(value: number, unit: UnitType): DayjsInstance
subtract(value: number, unit: UnitType): DayjsInstance
startOf(unit: UnitType): DayjsInstance
endOf(unit: UnitType): DayjsInstance
format(template?: string): string
diff(dayjs: DayjsInstance, unit: UnitType, float?: boolean): number
valueOf(): number
unix(): number
daysInMonth(): number
toDate(): Date
toArray(): number[]
toJSON(): string
toISOString(): string
toObject(): DayjsPlainObject
toString(): string
isBefore(dayjs: DayjsInstance, unit?: UnitType): boolean
isSame(dayjs: DayjsInstance, unit?: UnitType): boolean
isAfter(dayjs: DayjsInstance, unit?: UnitType): boolean
isLeapYear(): boolean
locale(arg1: any, arg2?: any): DayjsInstance
}

0 comments on commit 123c72d

Please sign in to comment.