You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
What should I do if I use
export default foo
syntax in TypeScript and want to havefoo
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 ofstandalone
so it can get mapped to the standalone export.Foe example if my module is this:
and I use tsify like this:
I'm expecting
add
exported to globalwindow
for browsers.The text was updated successfully, but these errors were encountered: