From 487db51268a961e1e729bf998b87bb98bdb6322e Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 4 Nov 2019 17:10:26 +0800 Subject: [PATCH 1/2] feat(ts): add missing locale type definitions --- .gitignore | 4 ++-- types/index.d.ts | 8 +++++--- types/locale/index.d.ts | 11 +++++++++++ types/locale/types.d.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 types/locale/index.d.ts create mode 100644 types/locale/types.d.ts diff --git a/.gitignore b/.gitignore index d022dbedb..7894e3925 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,9 @@ coverage # build /locale /plugin -dayjs.min.js +/dayjs.min.js /esm -index.d.ts +/index.d.ts #dev demo.js diff --git a/types/index.d.ts b/types/index.d.ts index ff664da55..c4ad33fcc 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,3 +1,5 @@ +/// + export = dayjs; declare function dayjs (date?: dayjs.ConfigType, option?: dayjs.OptionType, locale?: string): dayjs.Dayjs @@ -91,18 +93,18 @@ declare namespace dayjs { locale(): string - locale(preset: string | { name: string, [key: string]: any }, object?: { [key: string]: any }): Dayjs + locale(preset: string | ILocale, object?: ILocale): Dayjs } export type PluginFunc = (option: any, c: typeof Dayjs, d: typeof dayjs) => void export function extend(plugin: PluginFunc, option?: any): Dayjs - export function locale(preset: string | { name: string, [key: string]: any }, object?: { [key: string]: any }, isLocal?: boolean): string + export function locale(preset: string | ILocale, object?: ILocale, isLocal?: boolean): string export function isDayjs(d: any): d is Dayjs export function unix(t: number): Dayjs - const Ls : { [key: string] : { [key: string]: any } } + const Ls : { [key: string] : ILocale } } diff --git a/types/locale/index.d.ts b/types/locale/index.d.ts new file mode 100644 index 000000000..bd2dca2cd --- /dev/null +++ b/types/locale/index.d.ts @@ -0,0 +1,11 @@ +/// + +declare module 'dayjs/locale/*' { + namespace locale { + interface Locale extends ILocale {} + } + + const locale: locale.Locale + + export = locale +} diff --git a/types/locale/types.d.ts b/types/locale/types.d.ts new file mode 100644 index 000000000..50f65692c --- /dev/null +++ b/types/locale/types.d.ts @@ -0,0 +1,33 @@ +declare interface ILocale { + name: string + weekdays: string[] + months: string[] + weekStart: number + weekdaysShort: string[] + monthsShort: string[] + weekdaysMin: string[] + ordinal: (n: number) => number | string + formats: { + LT: string + LTS: string + L: string + LL: string + LLL: string + LLLL: string + } + relativeTime: { + future: string + past: string + s: string + m: string + mm: string + h: string + hh: string + d: string + dd: string + M: string + MM: string + y: string + yy: string + } +} From 78e81444694c6ea86e7683acc4ad97d1412774a9 Mon Sep 17 00:00:00 2001 From: JounQin Date: Wed, 6 Nov 2019 16:12:10 +0800 Subject: [PATCH 2/2] fix: name is required, but others are optional --- types/index.d.ts | 4 ++-- types/locale/types.d.ts | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index c4ad33fcc..a0f38c89d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -93,14 +93,14 @@ declare namespace dayjs { locale(): string - locale(preset: string | ILocale, object?: ILocale): Dayjs + locale(preset: string | ILocale, object?: Partial): Dayjs } export type PluginFunc = (option: any, c: typeof Dayjs, d: typeof dayjs) => void export function extend(plugin: PluginFunc, option?: any): Dayjs - export function locale(preset: string | ILocale, object?: ILocale, isLocal?: boolean): string + export function locale(preset: string | ILocale, object?: Partial, isLocal?: boolean): string export function isDayjs(d: any): d is Dayjs diff --git a/types/locale/types.d.ts b/types/locale/types.d.ts index 50f65692c..2c24a6456 100644 --- a/types/locale/types.d.ts +++ b/types/locale/types.d.ts @@ -1,21 +1,21 @@ declare interface ILocale { name: string - weekdays: string[] - months: string[] - weekStart: number - weekdaysShort: string[] - monthsShort: string[] - weekdaysMin: string[] - ordinal: (n: number) => number | string - formats: { + weekdays?: string[] + months?: string[] + weekStart?: number + weekdaysShort?: string[] + monthsShort?: string[] + weekdaysMin?: string[] + ordinal?: (n: number) => number | string + formats: Partial<{ LT: string LTS: string L: string LL: string LLL: string LLLL: string - } - relativeTime: { + }> + relativeTime: Partial<{ future: string past: string s: string @@ -29,5 +29,5 @@ declare interface ILocale { MM: string y: string yy: string - } + }> }