I've been attempting to add a function to the prototype of the Moment
interface in order to format it consistently every time it's used. I have already tried the solution mentioned here.
declare module moment {
export interface Moment {
myFormat: () => string;
}
}
In another file, I implemented it as follows:
Moment.prototype.myFormat = ():string => { return this.format("DD.MM.YYY"); }
However, this approach is not producing the desired results. My goal is to simply call moment(aDate).myFormat()
, but I am unable to get it working.
I have experimented with using declare module "moment"
and different variations of moment.Moment
, but the issue persists.
The example in the link does not include the use of declare
. However, when I omit it, I receive the following error message:
'declare' modifier required for top level element.