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

export default and standalone #105

Closed
mohsen1 opened this issue Dec 16, 2015 · 1 comment
Closed

export default and standalone #105

mohsen1 opened this issue Dec 16, 2015 · 1 comment
Labels

Comments

@mohsen1
Copy link

mohsen1 commented Dec 16, 2015

What should I do if I use export default foo syntax in TypeScript and want to have foo exported as standalone object?

According to microsoft/TypeScript#2719 there is a bit of conflict on what export default foo should do in TypeScript but Browserify has the concept of standalone so it can get mapped to the standalone export.

Foe example if my module is this:

export default function add(a: number, b: number): number { return a + b; }

and I use tsify like this:

browserify -p [tsify] --standalone add index.ts 

I'm expecting add exported to global window for browsers.

@smrq smrq added the question label Mar 8, 2016
@cartant
Copy link
Contributor

cartant commented Aug 24, 2016

I'm answering old question this so that I can close it. It's related to another issue on which I've recently been corresponding and I've only just noticed it.

If you have add.ts with this content:

export default function add(a: number, b: number): number { return a + b; }

this command:

browserify -p [tsify] --standalone add add.ts

will export a bundle with a global add object with a default property set to the function. That is, you'd need call the function like this:

add.default(1, 2);

To change things so that the add global is the function itself by using a JS file to require the TS file. If index.js has this content:

module.exports = require("./add").default;

this command:

browserify -p [tsify] --standalone add index.js

will export a bundle with a global add function. That is, you'd be able to call the function like this:

add(1, 2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants