Skip to content

Commit

Permalink
Proper support for null and undefined for typescript 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ichernev committed Nov 22, 2016
1 parent d739027 commit 2cfb22b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 7 additions & 9 deletions moment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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[];

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[];

Expand Down
8 changes: 8 additions & 0 deletions typing-tests/moment-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 2cfb22b

Please sign in to comment.