Using the techniques described in this question, I am attempting to use Moment.js to extend the Date
prototype in a TypeScript project.
Extending the Date
prototype works, as described:
interface Date {
myExtension: () => string;
}
if (!Date.prototype.myExtension) {
Date.prototype.myExtension = function(): string {
return 'some value derived from a date';
};
}
However, as soon as I import Moment.js, by adding the following line to my file, TypeScript invalidates my code, telling me that Property 'myExtension' does not exist on type 'Date'
.
import * as moment from 'moment';
Is there another way I should be declaring the Moment.js import?