I\'m not getting Aurelia (CLI) & TypeScript & MomentJS to work together. I\'ve seen solutions for Aurelia & Moment problems but they don\'t use the Aurelia CLI.
MomentJS is a global module, which exports a moment
variable only.
Other interface definitions in the d.ts file, e.g. interface Moment
, won't be exported for real. Those are there for the TypeScript compiler and intellisense.
That's why you've experienced TS compiler and TypeError issues above. You may've tricked the compiler with autoinject but not the browser.
moment's definition file:
declare module 'moment' {
var moment: moment.MomentStatic;
export = moment;
}
In order to get it working, use an import statement like this: [moment docs]
import * as moment from 'moment';
After that, the moment
variable becomes available and you can use it as you normally would.
Usage in your class:
import * as moment from 'moment';
export class App {
message = 'Hello World!';
constructor(){
}
hello() : string {
return moment().format();
}
}