Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing momentjs using jspm #5682

Closed
adrianhara opened this issue Nov 16, 2015 · 2 comments
Closed

Importing momentjs using jspm #5682

adrianhara opened this issue Nov 16, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@adrianhara
Copy link

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!

@adrianhara
Copy link
Author

Ah, it looks like it's actually this: #5285

@ahejlsberg
Copy link
Member

Yes, this is a duplicate of #5285. A fix is underway in #5577.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Nov 16, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants