]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Proper support for null and undefined for typescript 2.0
authorIskren Chernev <iskren.chernev@gmail.com>
Tue, 22 Nov 2016 13:22:35 +0000 (15:22 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 22 Nov 2016 13:22:35 +0000 (15:22 +0200)
moment.d.ts
typing-tests/moment-tests.ts

index 7b42fa18e7024fcdcea7249229331de59f1990b3..01aa7324b8d8905b361965f4ca2e34a4f22544fd 100644 (file)
@@ -248,12 +248,12 @@ declare namespace moment {
     overflow: number;
     charsLeftOver: number;
     nullInput: boolean;
-    invalidMonth: string;
+    invalidMonth: string | null;
     invalidFormat: boolean;
     userInvalidated: boolean;
     iso: boolean;
     parsedDateParts: any[];
-    meridiem: string;
+    meridiem: string | null;
   }
 
   interface MomentParsingFlagsOpt {
@@ -389,8 +389,8 @@ declare namespace moment {
     to: MomentInput;
   }
 
-  type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject;
-  type DurationInputArg1 = Duration | number | string | FromTo | DurationInputObject;
+  type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | null | undefined;
+  type DurationInputArg1 = Duration | number | string | FromTo | DurationInputObject | null | undefined;
   type DurationInputArg2 = unitOfTime.DurationConstructor;
   type LocaleSpecifier = string | Moment | Duration | string[];
 
@@ -632,12 +632,10 @@ declare namespace moment {
 
   export function locale(language?: string): string;
   export function locale(language?: string[]): string;
-  export function locale(language?: string, definition?: LocaleSpecification): string;
+  export function locale(language?: string, definition?: LocaleSpecification | null | undefined): string;
 
   export function localeData(key?: string | string[]): Locale;
 
-  export function updateLocale(language: string, locale: LocaleSpecification): Locale;
-
   export function duration(inp?: DurationInputArg1, unit?: DurationInputArg2): Duration;
 
   // NOTE(constructor): Same as moment constructor
@@ -686,8 +684,8 @@ declare namespace moment {
    */
   export function now(): number;
 
-  export function defineLocale(language: string, localeSpec: LocaleSpecification): Locale;
-  export function updateLocale(language: string, localeSpec: LocaleSpecification): Locale;
+  export function defineLocale(language: string, localeSpec: LocaleSpecification | null): Locale;
+  export function updateLocale(language: string, localeSpec: LocaleSpecification | null): Locale;
 
   export function locales(): string[];
 
index f22e1d2522f6a1f29721985e08d72747f93806a4..5a41aba01a09bd4a3a6080de2462db6f88fa4151 100644 (file)
@@ -22,6 +22,8 @@ var array = [2010, 1, 14, 15, 25, 50, 125];
 var day11 = moment(Date.UTC.apply({}, array));
 var day12 = moment.unix(1318781876);
 
+moment(null);
+moment(undefined);
 moment({ years: 2010, months: 3, days: 5, hours: 15, minutes: 10, seconds: 3, milliseconds: 123 });
 moment("20140101", "YYYYMMDD", true);
 moment("20140101", "YYYYMMDD", "en");
@@ -223,6 +225,8 @@ localLang.localeData();
 localLang.format('LLLL');
 globalLang.format('LLLL');
 
+moment.duration(null);
+moment.duration(undefined);
 moment.duration(100);
 moment.duration(2, 'seconds');
 moment.duration({
@@ -255,6 +259,10 @@ moment.locale();
 moment.locale('en');
 moment.locale(['en', 'fr']);
 
+moment.defineLocale('en', null);
+moment.updateLocale('en', null);
+moment.locale('en', null);
+
 // Defining a custom language:
 moment.locale('en', {
     months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],