diff --git a/src/add.pipe.ts b/src/add.pipe.ts index fa4a7b6..4d47c87 100644 --- a/src/add.pipe.ts +++ b/src/add.pipe.ts @@ -7,7 +7,7 @@ const momentConstructor = moment; @Pipe({ name: 'amAdd' }) export class AddPipe implements PipeTransform { - transform(value: any, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any { + transform(value: moment.MomentInput, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any { if (typeof amount === 'undefined' || (typeof amount === 'number' && typeof unit === 'undefined')) { throw new Error('AddPipe: missing required arguments'); } diff --git a/src/calendar.pipe.ts b/src/calendar.pipe.ts index c475027..2246825 100644 --- a/src/calendar.pipe.ts +++ b/src/calendar.pipe.ts @@ -32,7 +32,7 @@ export class CalendarPipe implements PipeTransform, OnDestroy { }); } - transform(value: Date | moment.Moment, ...args: any[]): any { + transform(value: moment.MomentInput, ...args: any[]): any { let formats: any = null; let referenceTime: any = null; diff --git a/src/date-format.pipe.ts b/src/date-format.pipe.ts index ca5b83a..f88415b 100644 --- a/src/date-format.pipe.ts +++ b/src/date-format.pipe.ts @@ -7,7 +7,7 @@ const momentConstructor = moment; @Pipe({ name: 'amDateFormat' }) export class DateFormatPipe implements PipeTransform { - transform(value: Date | moment.Moment | string | number, ...args: any[]): string { + transform(value: moment.MomentInput, ...args: any[]): string { if (!value) { return ''; } return momentConstructor(value).format(args[0]); } diff --git a/src/difference.pipe.ts b/src/difference.pipe.ts index 969fcb1..f29e8a3 100644 --- a/src/difference.pipe.ts +++ b/src/difference.pipe.ts @@ -7,8 +7,8 @@ const momentConstructor = moment; @Pipe({ name: 'amDifference' }) export class DifferencePipe implements PipeTransform { - transform(value: Date | moment.Moment, - otherValue: Date | moment.Moment, + transform(value: moment.MomentInput, + otherValue: moment.MomentInput, unit?: moment.unitOfTime.Diff, precision?: boolean): number { diff --git a/src/duration.pipe.ts b/src/duration.pipe.ts index 72035f6..12c1321 100644 --- a/src/duration.pipe.ts +++ b/src/duration.pipe.ts @@ -12,7 +12,7 @@ export class DurationPipe implements PipeTransform { this._applyOptions(momentOptions); } - transform(value: any, ...args: string[]): string { + transform(value: moment.DurationInputArg1, ...args: string[]): string { if (typeof args === 'undefined' || args.length !== 1) { throw new Error('DurationPipe: missing required time unit argument'); } diff --git a/src/from-unix.pipe.ts b/src/from-unix.pipe.ts index 1334dec..8a5570f 100644 --- a/src/from-unix.pipe.ts +++ b/src/from-unix.pipe.ts @@ -5,10 +5,7 @@ import * as moment from 'moment'; @Pipe({ name: 'amFromUnix' }) export class FromUnixPipe implements PipeTransform { - transform(value: any, ...args: string[]): any { - if (typeof value === 'string') { - value = +value; - } - return moment.unix(value); + transform(value: number | string, ...args: string[]): any { + return (typeof value === 'string') ? moment.unix(parseInt(value, 10)) : moment.unix(value); } } diff --git a/src/from-utc.pipe.ts b/src/from-utc.pipe.ts index b00cfbb..657efff 100644 --- a/src/from-utc.pipe.ts +++ b/src/from-utc.pipe.ts @@ -5,7 +5,7 @@ import * as moment from 'moment'; @Pipe({ name: 'amFromUtc' }) export class FromUtcPipe implements PipeTransform { - transform(value: any, formats?: string|string[], ...args: string[]): any { + transform(value: moment.MomentInput, formats?: string|string[], ...args: string[]): any { return formats ? moment.utc(value, formats) : moment.utc(value); } } diff --git a/src/is-after.pipe.ts b/src/is-after.pipe.ts index 3364df1..21ec1d9 100644 --- a/src/is-after.pipe.ts +++ b/src/is-after.pipe.ts @@ -9,8 +9,8 @@ const momentConstructor = moment; }) export class IsAfterPipe implements PipeTransform { - transform(value: Date | moment.Moment, - otherValue: Date | moment.Moment, + transform(value: moment.MomentInput, + otherValue: moment.MomentInput, unit?: moment.unitOfTime.StartOf): boolean { return momentConstructor(value).isAfter(momentConstructor(otherValue), unit); } diff --git a/src/is-before.pipe.ts b/src/is-before.pipe.ts index d8f53ac..608c34e 100644 --- a/src/is-before.pipe.ts +++ b/src/is-before.pipe.ts @@ -9,8 +9,8 @@ const momentConstructor = moment; }) export class IsBeforePipe implements PipeTransform { - transform(value: Date | moment.Moment, - otherValue: Date | moment.Moment, + transform(value: moment.MomentInput, + otherValue: moment.MomentInput, unit?: moment.unitOfTime.StartOf): boolean { return momentConstructor(value).isBefore(momentConstructor(otherValue), unit); } diff --git a/src/local.pipe.ts b/src/local.pipe.ts index 4a80b4d..e55b696 100644 --- a/src/local.pipe.ts +++ b/src/local.pipe.ts @@ -5,7 +5,7 @@ const momentConstructor = moment; @Pipe({ name: 'amLocal' }) export class LocalTimePipe implements PipeTransform { - transform(value: Date | moment.Moment | string | number): moment.Moment { + transform(value: moment.MomentInput): moment.Moment { return momentConstructor(value).local(); } } diff --git a/src/locale.pipe.ts b/src/locale.pipe.ts index b568835..94f86ce 100644 --- a/src/locale.pipe.ts +++ b/src/locale.pipe.ts @@ -1,12 +1,12 @@ import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; -// under systemjs, moment is actually exported as the default export, so we account for that +// See https://github.com/ng-packagr/ng-packagr/issues/217 for why this is needed: const momentConstructor = moment; @Pipe({ name: 'amLocale' }) export class LocalePipe implements PipeTransform { - transform(value: string | Date, locale: string): moment.Moment { + transform(value: moment.MomentInput, locale: string): moment.Moment { return momentConstructor(value).locale(locale); } } diff --git a/src/parse-zone.pipe.ts b/src/parse-zone.pipe.ts index 187f564..a3d67aa 100644 --- a/src/parse-zone.pipe.ts +++ b/src/parse-zone.pipe.ts @@ -3,7 +3,7 @@ import * as moment from 'moment'; @Pipe({ name: 'amParseZone' }) export class ParseZonePipe implements PipeTransform { - transform(value: string): moment.Moment { + transform(value: moment.MomentInput): moment.Moment { return moment.parseZone(value); } } diff --git a/src/parse.pipe.ts b/src/parse.pipe.ts index edd5b58..c4649ff 100644 --- a/src/parse.pipe.ts +++ b/src/parse.pipe.ts @@ -5,7 +5,7 @@ const momentConstructor = moment; @Pipe({ name: 'amParse' }) export class ParsePipe implements PipeTransform { - transform(value: string, formats: string|string[]): moment.Moment { + transform(value: moment.MomentInput, formats: string|string[]): moment.Moment { return momentConstructor(value, formats); } } diff --git a/src/subtract.pipe.ts b/src/subtract.pipe.ts index 43d5250..3550f26 100644 --- a/src/subtract.pipe.ts +++ b/src/subtract.pipe.ts @@ -7,7 +7,7 @@ const momentConstructor = moment; @Pipe({ name: 'amSubtract' }) export class SubtractPipe implements PipeTransform { - transform(value: any, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any { + transform(value: moment.MomentInput, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any { if (typeof amount === 'undefined' || (typeof amount === 'number' && typeof unit === 'undefined')) { throw new Error('SubtractPipe: missing required arguments'); } diff --git a/src/utc.pipe.ts b/src/utc.pipe.ts index faf3545..f062f37 100644 --- a/src/utc.pipe.ts +++ b/src/utc.pipe.ts @@ -5,7 +5,7 @@ const momentConstructor = moment; @Pipe({ name: 'amUtc' }) export class UtcPipe implements PipeTransform { - transform(value: Date | moment.Moment | string | number): moment.Moment { + transform(value: moment.MomentInput): moment.Moment { return momentConstructor(value).utc(); } }