Skip to content

Commit a61e766

Browse files
FourwingsYmhegazy
authored andcommitted
[@types/luxon] update types (#22463)
* fix types of luxon * fix Settings make Settings.defaultZone as readonly, change expression of Settings.now * fix static-only classes to namespace * fix unused lint rules
1 parent 9a3fbe8 commit a61e766

4 files changed

Lines changed: 103 additions & 77 deletions

File tree

types/luxon/index.d.ts

Lines changed: 79 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
// Type definitions for luxon 0.2
22
// Project: https://github.com/moment/luxon#readme
33
// Definitions by: Colby DeHart <https://github.com/colbydehart>
4+
// Hyeonseok Yang <https://github.com/FourwingsY>
45
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6+
// TypeScript Version: 2.2
57

68
declare module 'luxon' {
79
namespace luxon {
8-
type DateTimeFormat = any;
10+
type DateTimeFormatOptions = Intl.DateTimeFormatOptions;
11+
912
type ZoneOptions = {
1013
keepCalendarTime?: boolean;
1114
};
1215

13-
type ToFormatOptions = {
14-
round: boolean;
16+
type ToFormatOptions = DateTimeFormatOptions & {
17+
round?: boolean;
1518
};
1619

1720
type ISOTimeOptions = {
1821
suppressMilliseconds?: boolean;
19-
supressSeconds?: boolean;
22+
suppressSeconds?: boolean;
23+
includeOffset?: boolean;
2024
};
2125

22-
type DateTimeOptions = {
23-
zone?: string | Zone;
24-
setZone?: boolean;
26+
type LocaleOptions = {
2527
locale?: string;
2628
outputCalendar?: string;
2729
numberingSystem?: string;
2830
};
2931

30-
type DateTimeJSOptions = {
32+
type DateTimeOptions = LocaleOptions & {
33+
zone?: string | Zone;
34+
setZone?: boolean;
35+
};
36+
37+
type DateTimeJSOptions = LocaleOptions & {
3138
zone?: string | Zone;
3239
};
3340

3441
type DateObjectUnits = {
3542
year?: number;
43+
month?: number;
3644
day?: number;
3745
ordinal?: number;
3846
weekYear?: number;
@@ -44,38 +52,35 @@ declare module 'luxon' {
4452
millisecond?: number;
4553
};
4654

47-
type DateObject = DateObjectUnits & {
55+
type DateObject = DateObjectUnits & LocaleOptions & {
4856
zone?: string | Zone;
49-
locale?: string;
50-
outputCalendar?: string;
51-
numberingSystem?: string;
5257
};
5358

5459
type DiffOptions = {
5560
conversionAccuracy?: string;
5661
};
5762

5863
class DateTime {
59-
static DATETIME_FULL: DateTimeFormat;
60-
static DATETIME_FULL_WITH_SECONDS: DateTimeFormat;
61-
static DATEIME_HUGE: DateTimeFormat;
62-
static DATEIME_HUGE_WITH_SECONDS: DateTimeFormat;
63-
static DATETIME_MED: DateTimeFormat;
64-
static DATETIME_MED_WITH_SECONDS: DateTimeFormat;
65-
static DATETIME_SHORT: DateTimeFormat;
66-
static DATETIME_SHORT_WITH_SECONDS: DateTimeFormat;
67-
static DATE_FULL: DateTimeFormat;
68-
static DATE_HUGE: DateTimeFormat;
69-
static DATE_MED: DateTimeFormat;
70-
static DATE_SHORT: DateTimeFormat;
71-
static TIME_24_SIMPLE: DateTimeFormat;
72-
static TIME_24_WITH_LONG_OFFSET: DateTimeFormat;
73-
static TIME_24_WITH_SECONDS: DateTimeFormat;
74-
static TIME_24_WITH_SHORT_OFFSET: DateTimeFormat;
75-
static TIME_SIMPLE: DateTimeFormat;
76-
static TIME_WITH_LONG_OFFSET: DateTimeFormat;
77-
static TIME_WITH_SECONDS: DateTimeFormat;
78-
static TIME_WITH_SHORT_OFFSET: DateTimeFormat;
64+
static DATETIME_FULL: DateTimeFormatOptions;
65+
static DATETIME_FULL_WITH_SECONDS: DateTimeFormatOptions;
66+
static DATEIME_HUGE: DateTimeFormatOptions;
67+
static DATEIME_HUGE_WITH_SECONDS: DateTimeFormatOptions;
68+
static DATETIME_MED: DateTimeFormatOptions;
69+
static DATETIME_MED_WITH_SECONDS: DateTimeFormatOptions;
70+
static DATETIME_SHORT: DateTimeFormatOptions;
71+
static DATETIME_SHORT_WITH_SECONDS: DateTimeFormatOptions;
72+
static DATE_FULL: DateTimeFormatOptions;
73+
static DATE_HUGE: DateTimeFormatOptions;
74+
static DATE_MED: DateTimeFormatOptions;
75+
static DATE_SHORT: DateTimeFormatOptions;
76+
static TIME_24_SIMPLE: DateTimeFormatOptions;
77+
static TIME_24_WITH_LONG_OFFSET: DateTimeFormatOptions;
78+
static TIME_24_WITH_SECONDS: DateTimeFormatOptions;
79+
static TIME_24_WITH_SHORT_OFFSET: DateTimeFormatOptions;
80+
static TIME_SIMPLE: DateTimeFormatOptions;
81+
static TIME_WITH_LONG_OFFSET: DateTimeFormatOptions;
82+
static TIME_WITH_SECONDS: DateTimeFormatOptions;
83+
static TIME_WITH_SHORT_OFFSET: DateTimeFormatOptions;
7984
static fromHTTP(text: string, options?: DateTimeOptions): DateTime;
8085
static fromISO(text: string, options?: DateTimeOptions): DateTime;
8186
static fromJSDate(
@@ -98,7 +103,7 @@ declare module 'luxon' {
98103
text: string,
99104
format: string,
100105
options?: DateTimeOptions
101-
): Object;
106+
): object;
102107
static invalid(reason: any): DateTime;
103108
static local(
104109
year?: number,
@@ -110,7 +115,7 @@ declare module 'luxon' {
110115
millisecond?: number
111116
): DateTime;
112117
static max(...dateTimes: DateTime[]): DateTime | undefined;
113-
static min(...dateTimes: DateTime[]): DateTime;
118+
static min(...dateTimes: DateTime[]): DateTime | undefined;
114119
static utc(
115120
year?: number,
116121
month?: number,
@@ -138,12 +143,12 @@ declare module 'luxon' {
138143
offset: number;
139144
offsetNameLong: string;
140145
offsetNameShort: string;
141-
ordinal: number | DateTime;
146+
ordinal: number;
142147
outputCalendar: string;
143148
second: number;
144149
weekNumber: number;
145150
weekYear: number;
146-
weekday: string;
151+
weekday: number;
147152
weekdayLong: string;
148153
weekdayShort: string;
149154
year: number;
@@ -158,27 +163,25 @@ declare module 'luxon' {
158163
equals(other: DateTime): boolean;
159164
get(unit: string): number;
160165
hasSame(other: DateTime, unit: string): boolean;
161-
minus(duration: Duration): DateTime;
162-
minus(milliseconds: number): DateTime;
163-
minus(durationObject: DurationObject): DateTime;
164-
plus(duration: Duration | number | Object): DateTime;
165-
reconfigure(properties: Object): DateTime;
166-
resolvedLocaleOptions(options?: Object): Object;
166+
minus(duration: Duration | number | DurationObject): DateTime;
167+
plus(duration: Duration | number | DurationObject): DateTime;
168+
reconfigure(properties: LocaleOptions): DateTime;
169+
resolvedLocaleOpts(options?: ToFormatOptions): LocaleOptions;
167170
set(values: DateObjectUnits): DateTime;
168171
setLocale(locale: any): DateTime;
169172
setZone(zone: string | Zone, options?: ZoneOptions): DateTime;
170173
startOf(unit: string): DateTime;
171174
toFormat(format: string, options?: ToFormatOptions): string;
172175
toHTTP(): string;
173-
toISO(options?: Object): string;
176+
toISO(options?: ISOTimeOptions): string;
174177
toISODate(): string;
175178
toISOTime(options?: ISOTimeOptions): string;
176179
toISOWeekDate(): string;
177180
toJSDate(): Date;
178181
toJSON(): string;
179182
toLocal(): DateTime;
180-
toLocaleParts(options?: Object): any[];
181-
toLocaleString(options?: DateTimeFormat): string;
183+
toLocaleParts(options?: DateTimeFormatOptions): any[];
184+
toLocaleString(options?: DateTimeFormatOptions): string;
182185
toObject(options?: { includeConfig?: boolean }): DateObject;
183186
toRFC2822(): string;
184187
toSQL(options?: Object): string;
@@ -196,7 +199,7 @@ declare module 'luxon' {
196199
conversionAccuracy?: string;
197200
};
198201

199-
type DurationObject = {
202+
type DurationObjectUnits = {
200203
years?: number;
201204
months?: number;
202205
weeks?: number;
@@ -207,14 +210,16 @@ declare module 'luxon' {
207210
milliseconds?: number;
208211
};
209212

213+
type DurationObject = DurationObjectUnits & DurationOptions;
214+
210215
class Duration {
211216
static fromISO(text: string, options?: DurationOptions): Duration;
212217
static fromMillis(
213218
count: number,
214219
options?: DurationOptions
215220
): Duration;
216221
static fromObject(
217-
Object: DurationObject & DurationOptions
222+
Object: DurationObject
218223
): Duration;
219224
static invalid(reason?: string): Duration;
220225
days: number;
@@ -232,24 +237,24 @@ declare module 'luxon' {
232237
as(unit: string): number;
233238
equals(other: Duration): boolean;
234239
get(unit: string): number;
235-
minus(duration: Duration | number | Object): Duration;
240+
minus(duration: Duration | number | DurationObject): Duration;
236241
negate(): Duration;
237242
normalize(): Duration;
238-
plus(duration: Duration | number | Object): Duration;
243+
plus(duration: Duration | number | DurationObject): Duration;
239244
reconfigure(objectPattern: DurationOptions): Duration;
240-
set(values: DurationObject): Duration;
245+
set(values: DurationObjectUnits): Duration;
241246
shiftTo(...units: string[]): Duration;
242247
toFormat(format: string, options?: ToFormatOptions): string;
243248
toISO(): string;
244249
toJSON(): string;
245250
toObject(options?: {
246251
includeConfig?: boolean;
247-
}): DurationObject & DurationOptions;
252+
}): DurationObject;
248253
toString(): string;
249254
}
250255

251256
type EraLength = 'short' | 'long';
252-
type UnitLength = EraLength & 'numeric' | '2-digit' | 'narrow';
257+
type UnitLength = EraLength | 'numeric' | '2-digit' | 'narrow';
253258
type UnitOptions = InfoOptions & {
254259
numberingSystem?: string;
255260
outputCalendar?: string;
@@ -265,19 +270,19 @@ declare module 'luxon' {
265270
timezones: boolean;
266271
};
267272

268-
type Info = {
269-
eras(length?: EraLength, options?: InfoOptions): string[];
270-
features(): Features;
271-
hasDST(zone: string | Zone): boolean;
272-
meridiems(options?: InfoOptions): string[];
273-
months(length?: UnitLength, options?: UnitOptions): string[];
274-
monthsFormat(length?: UnitLength, options?: UnitOptions): string[];
275-
weeksdays(length?: UnitLength, options?: UnitOptions): string[];
276-
weekdaysFormat(
273+
namespace Info {
274+
function eras(length?: EraLength, options?: InfoOptions): string[];
275+
function features(): Features;
276+
function hasDST(zone: string | Zone): boolean;
277+
function meridiems(options?: InfoOptions): string[];
278+
function months(length?: UnitLength, options?: UnitOptions): string[];
279+
function monthsFormat(length?: UnitLength, options?: UnitOptions): string[];
280+
function weekdays(length?: UnitLength, options?: UnitOptions): string[];
281+
function weekdaysFormat(
277282
length?: UnitLength,
278283
options?: UnitOptions
279284
): string[];
280-
};
285+
}
281286

282287
type IntervalObject = {
283288
start: DateTime;
@@ -333,21 +338,21 @@ declare module 'luxon' {
333338
seperator?: string;
334339
}
335340
): string;
336-
toISO(options?: Object): string;
341+
toISO(options?: ISOTimeOptions): string;
337342
toString(): string;
338343
union(other: Interval): Interval;
339344
}
340345

341-
type Settings = {
342-
defaultLocale: string;
343-
defaultNumberingSystem: string;
344-
defaultOutputCalendar: string;
345-
defaultZone: Zone;
346-
defaultZoneName: string;
347-
now: Function;
348-
throwOnInvalid: boolean;
349-
resetCache(): void;
350-
};
346+
namespace Settings {
347+
let defaultLocale: string;
348+
let defaultNumberingSystem: string;
349+
let defaultOutputCalendar: string;
350+
const defaultZone: Zone;
351+
let defaultZoneName: string;
352+
let throwOnInvalid: boolean;
353+
let now: () => number;
354+
function resetCache(): void;
355+
}
351356

352357
type ZoneOffsetOptions = {
353358
format?: 'short' | 'long';
@@ -361,7 +366,7 @@ declare module 'luxon' {
361366
static type: string;
362367
static universal: boolean;
363368
equals(other: Zone): boolean;
364-
static offset(ts: number): number;
369+
offset(ts: number): number;
365370
}
366371
}
367372

types/luxon/luxon-tests.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { DateTime, Duration, Interval } from 'luxon';
1+
import { DateTime, Duration, Interval, Info, Settings } from 'luxon';
22

3+
/* DateTime */
34
const dt = DateTime.local(2017, 5, 15, 8, 30);
45

56
const now = DateTime.local();
67

78
const fromObject = DateTime.fromObject({
9+
month: 4,
810
day: 22,
911
hour: 12,
1012
zone: 'America/Los_Angeles',
@@ -25,10 +27,12 @@ getters.weekday;
2527
getters.zoneName;
2628
getters.offset;
2729
getters.daysInMonth;
30+
getters.ordinal;
2831

2932
dt.toLocaleString();
3033
dt.toLocaleString(DateTime.DATE_MED);
3134
dt.toISO();
35+
dt.toISO({includeOffset: true});
3236

3337
dt.plus({ hours: 3, minutes: 2 });
3438
dt.minus({ days: 7 });
@@ -50,6 +54,7 @@ DateTime.utc();
5054
DateTime.local().toUTC();
5155
DateTime.utc().toLocal();
5256

57+
/* Duration */
5358
const dur = Duration.fromObject({ hours: 2, minutes: 7 });
5459
dt.plus(dur);
5560
dur.hours;
@@ -60,6 +65,7 @@ dur.as('seconds');
6065
dur.toObject();
6166
dur.toISO();
6267

68+
/* Interval */
6369
const later = DateTime.local();
6470
const i = Interval.fromDateTimes(now, later);
6571
i.length();
@@ -68,3 +74,19 @@ i.contains(DateTime.local(2019));
6874

6975
i.toISO();
7076
i.toString();
77+
78+
/* Info */
79+
Info.months();
80+
Info.weekdays('long');
81+
82+
/* Settings */
83+
Settings.defaultLocale;
84+
Settings.defaultLocale = 'en';
85+
Settings.defaultZoneName = 'Europe/Paris';
86+
Settings.now();
87+
Settings.now = () => 0;
88+
89+
// $ExpectError
90+
Settings.defaultZone = Settings.defaultZone;
91+
92+
/* Zone */

types/luxon/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
"index.d.ts",
2121
"luxon-tests.ts"
2222
]
23-
}
23+
}

types/luxon/tslint.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"ban-types": false,
55
"no-single-declare-module": false,
66
"interface-over-type-literal": false,
7-
"unified-signatures": false,
87
"no-declare-current-package": false
98
}
109
}

0 commit comments

Comments
 (0)