# Cleaner way to get moment working with Typescript and Aurelia?

**URL:** <https://discourse.aurelia.io/t/cleaner-way-to-get-moment-working-with-typescript-and-aurelia/2538>\
**Category:** Help Requests\
**Created:** [May 10, 2019, 8:01pm UTC](https://discourse.aurelia.io/t/cleaner-way-to-get-moment-working-with-typescript-and-aurelia/2538 "2019-05-10T20:01:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roddharris](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/roddharris/32/1340_2.png) [@roddharris](https://discourse.aurelia.io/u/roddharris)\
**Post date:** [May 10, 2019, 8:01pm UTC](https://discourse.aurelia.io/t/cleaner-way-to-get-moment-working-with-typescript-and-aurelia/2538/1 "2019-05-10T20:01:01Z")

</div>

I’m using Aurelia with TypeScript and trying to import `momentjs`. I had this working in older (non-TypeScript) projects with the line `import moment from 'moment'`. However, this doesn’t seem to work with TypeScript.

I then found [this link](https://github.com/aurelia/skeleton-navigation/issues/606) and one of the examples showed the following:

```
import * as moment from 'moment';

export class DateFormatValueConverter {
    toView(value){
        return (moment as any).default(value).format("MM DD, YYYY");
    }
} 

```

That works – but wow is it ugly. Is there a cleaner way to work with momentjs and TypeScript within Aurelia?

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [May 10, 2019, 10:04pm UTC](https://discourse.aurelia.io/t/cleaner-way-to-get-moment-working-with-typescript-and-aurelia/2538/2 "2019-05-10T22:04:47Z")

</div>

I usually do barrel export for difficult vendor libs with difficult typings:

```auto
// vendor.moment.ts
import * as moment from 'moment';

export { moment }

```

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [May 11, 2019, 4:47am UTC](https://discourse.aurelia.io/t/cleaner-way-to-get-moment-working-with-typescript-and-aurelia/2538/3 "2019-05-11T04:47:09Z")

</div>

TS has a compiler option esModuleInterop to simplify import since v2.7.

[https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html)

Turn it on in tsconfig.json like this:

```json
{
  "compilerOptions": {
    "esModuleInterop": true
  }
}

```

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [May 11, 2019, 9:04am UTC](https://discourse.aurelia.io/t/cleaner-way-to-get-moment-working-with-typescript-and-aurelia/2538/4 "2019-05-11T09:04:37Z")

</div>

Yes, for node app i would use this because its full of this kind in node development. Though i think its not the best way to do it as it hides whats really being exported from the target module
