Skip to content

Importing momentjs using jspm #5682

@adrianhara

Description

@adrianhara

I'm using TS 1.6.3 and JSPM. I jspm install-ed moment and then import it like so
import * as moment from 'moment'

This compiles to

....
function(moment_1) {
    moment = moment_1;
}
....

Using Babel this compiles to

....
function(_moment) {
    moment = _moment['default'];
}
....

At runtime the moment_1 or _moment variable refers to an object which actually has a default property which is the MomentJS's factory. So, to me, it looks like Babel is correct.

As a result of the way the TS compiler compiles it, it's not possible, in TypeScript code, to simply do var x = moment() because at runtime that will fail as moment will be an object, not a function. You also can't do moment.default() because in the d.ts file there is no default function. At the moment I'm doing a hack (moment as any).default().

I would appreciate it if someone could shed some light on whether I'm doing something wrong or it's a bug.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions