mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
fix(types): add explicit types for extendedDayjs plugin methods (#37923)
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
import dayjs, { Dayjs, ConfigType } from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import timezone from 'dayjs/plugin/timezone';
|
||||
import calendar from 'dayjs/plugin/calendar';
|
||||
@@ -40,8 +40,42 @@ dayjs.updateLocale('en', {
|
||||
invalidDate: 'Invalid date',
|
||||
});
|
||||
|
||||
export const extendedDayjs = dayjs;
|
||||
export type { Dayjs };
|
||||
// Extended Dayjs instance type with plugin methods.
|
||||
// When extending dayjs with a new plugin, add its instance methods here.
|
||||
export interface ExtendedDayjs extends Dayjs {
|
||||
// Derived from dayjs/plugin/utc
|
||||
utc(keepLocalTime?: boolean): ExtendedDayjs;
|
||||
local(): ExtendedDayjs;
|
||||
isUTC(): boolean;
|
||||
// Derived from dayjs/plugin/timezone
|
||||
tz(timezone?: string, keepLocalTime?: boolean): ExtendedDayjs;
|
||||
// Derived from dayjs/plugin/relativeTime
|
||||
fromNow(withoutSuffix?: boolean): string;
|
||||
toNow(withoutSuffix?: boolean): string;
|
||||
from(compared: ConfigType, withoutSuffix?: boolean): string;
|
||||
to(compared: ConfigType, withoutSuffix?: boolean): string;
|
||||
// Derived from dayjs/plugin/calendar
|
||||
calendar(referenceTime?: ConfigType, formats?: object): string;
|
||||
}
|
||||
|
||||
// Type for dayjs factory with all plugins loaded.
|
||||
// When extending dayjs with a new plugin, add its static methods here.
|
||||
type DayjsWithPlugins = {
|
||||
(config?: ConfigType, format?: string, strict?: boolean): ExtendedDayjs;
|
||||
// Derived from dayjs/plugin/utc
|
||||
utc(config?: ConfigType, format?: string, strict?: boolean): ExtendedDayjs;
|
||||
// Derived from dayjs/plugin/timezone
|
||||
tz: {
|
||||
(input?: ConfigType, timezone?: string): ExtendedDayjs;
|
||||
guess(): string;
|
||||
setDefault(timezone?: string): void;
|
||||
};
|
||||
// Derived from dayjs/plugin/updateLocale
|
||||
updateLocale(locale: string, config: object): object;
|
||||
} & Omit<typeof dayjs, 'utc' | 'tz'>;
|
||||
|
||||
export const extendedDayjs = dayjs as unknown as DayjsWithPlugins;
|
||||
export type { Dayjs, ConfigType };
|
||||
|
||||
export const fDuration = function (
|
||||
t1: number,
|
||||
|
||||
Reference in New Issue
Block a user