diff --git a/moment.d.ts b/moment.d.ts index 7b42fa18e7..01aa7324b8 100644 --- a/moment.d.ts +++ b/moment.d.ts @@ -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[]; diff --git a/typing-tests/moment-tests.ts b/typing-tests/moment-tests.ts index f22e1d2522..5a41aba01a 100644 --- a/typing-tests/moment-tests.ts +++ b/typing-tests/moment-tests.ts @@ -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"],