From 8445819eb4a3fc76e1da08287dd0393072d99a2b Mon Sep 17 00:00:00 2001 From: Valerii Sidorenko Date: Wed, 8 Feb 2023 11:16:03 +0100 Subject: [PATCH] fix: properly export types dependent on dayjs plugins (#14) --- src/constants/timeZone.ts | 2 +- src/dateTime/dateTime.ts | 6 ++++-- src/datemath/datemath.test.ts | 2 +- src/dayjs.ts | 16 +++++++++++++++- src/parser/parser.ts | 2 +- src/settings/types.ts | 6 ++---- src/timeZone/timeZone.ts | 2 +- src/typings/common.ts | 2 +- src/typings/parser.ts | 4 ++-- tsconfig.json | 1 + 10 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/constants/timeZone.ts b/src/constants/timeZone.ts index 15dfdf0..3c0c3d8 100644 --- a/src/constants/timeZone.ts +++ b/src/constants/timeZone.ts @@ -1,3 +1,3 @@ -import {TimeZone} from '../typings'; +import type {TimeZone} from '../typings'; export const UtcTimeZone: TimeZone = 'UTC'; diff --git a/src/dateTime/dateTime.ts b/src/dateTime/dateTime.ts index 1457c9e..206c1ee 100644 --- a/src/dateTime/dateTime.ts +++ b/src/dateTime/dateTime.ts @@ -1,8 +1,10 @@ -import dayjs, {ConfigType} from '../dayjs'; -import {DateTime, DateTimeInput, FormatInput, TimeZone} from '../typings'; +import dayjs from '../dayjs'; import {STRICT, UtcTimeZone} from '../constants'; import {compareStrings} from '../utils'; +import type {ConfigType} from '../dayjs'; +import type {DateTime, DateTimeInput, FormatInput, TimeZone} from '../typings'; + export const createDateTime = ( input?: DateTimeInput, format?: FormatInput, diff --git a/src/datemath/datemath.test.ts b/src/datemath/datemath.test.ts index 7041df9..f13eb71 100644 --- a/src/datemath/datemath.test.ts +++ b/src/datemath/datemath.test.ts @@ -6,7 +6,7 @@ import {each} from 'lodash'; import {dateTime} from '../dateTime'; import * as dateMath from './datemath'; -import {DurationUnit, DateTime} from '../typings'; +import type {DurationUnit, DateTime} from '../typings'; describe('DateMath', () => { const spans: DurationUnit[] = ['s', 'm', 'h', 'd', 'w', 'M', 'Q', 'y']; diff --git a/src/dayjs.ts b/src/dayjs.ts index e1893cc..4a94802 100644 --- a/src/dayjs.ts +++ b/src/dayjs.ts @@ -24,4 +24,18 @@ dayjs.extend(updateLocale); // but not vice versa, therefore it should come last dayjs.extend(objectSupport); -export = dayjs; +export default dayjs; + +export type {ConfigTypeMap, ConfigType} from 'dayjs'; +export type { + arraySupport, + customParseFormat, + isoWeek, + quarterOfYear, + relativeTime, + timezone, + utc, + localizedFormat, + updateLocale, + objectSupport, +}; diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 5c4b4d0..5d38a24 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -4,7 +4,7 @@ import dayjs from '../dayjs'; import {dateTime} from '../dateTime'; import {parse, isValid} from '../datemath'; -import {DateTimeOptionsWhenParsing, DateTime, DateTimeParser} from '../typings'; +import type {DateTimeOptionsWhenParsing, DateTime, DateTimeParser} from '../typings'; const parseInput: DateTimeParser = ( input, diff --git a/src/settings/types.ts b/src/settings/types.ts index 4a0bb96..16276ba 100644 --- a/src/settings/types.ts +++ b/src/settings/types.ts @@ -1,6 +1,4 @@ -import dayjs from '../dayjs'; +import type dayjs from '../dayjs'; // https://dayjs.gitee.io/docs/ru/customization/customization -export type UpdateLocaleConfig = Parameters[1] & { - weekStart?: number; -}; +export type UpdateLocaleConfig = Parameters[1] | Partial; diff --git a/src/timeZone/timeZone.ts b/src/timeZone/timeZone.ts index ccd2951..f6de205 100644 --- a/src/timeZone/timeZone.ts +++ b/src/timeZone/timeZone.ts @@ -1,6 +1,6 @@ import dayjs from '../dayjs'; import {UtcTimeZone} from '../constants'; -import {TimeZone, TimeZoneOptions} from '../typings'; +import type {TimeZone, TimeZoneOptions} from '../typings'; export const getTimeZone = (options?: T): TimeZone => { return options?.timeZone ?? UtcTimeZone; diff --git a/src/typings/common.ts b/src/typings/common.ts index 1a87ecd..2dbe7ed 100644 --- a/src/typings/common.ts +++ b/src/typings/common.ts @@ -1,7 +1,7 @@ // Copyright 2015 Grafana Labs // Copyright 2021 YANDEX LLC -import {TimeZoneOptions} from './timeZone'; +import type {TimeZoneOptions} from './timeZone'; export interface DateTimeOptions extends TimeZoneOptions { /** diff --git a/src/typings/parser.ts b/src/typings/parser.ts index f0402b7..3cb40aa 100644 --- a/src/typings/parser.ts +++ b/src/typings/parser.ts @@ -1,8 +1,8 @@ // Copyright 2015 Grafana Labs // Copyright 2021 YANDEX LLC -import {DateTimeOptions} from './common'; -import {DateTime, DateTimeInput} from './dateTime'; +import type {DateTimeOptions} from './common'; +import type {DateTime, DateTimeInput} from './dateTime'; export type DateTimeParser = ( value: DateTimeInput, diff --git a/tsconfig.json b/tsconfig.json index 18c379d..0c2afda 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "target": "es5", "allowJs": false, "declaration": true, + "importsNotUsedAsValues": "error", "outDir": "build" }, "include": [