Skip to content

Why tsc compiles export default xyz to xyz.default? #17283

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

Closed
zikaari opened this issue Jul 19, 2017 · 4 comments
Closed

Why tsc compiles export default xyz to xyz.default? #17283

zikaari opened this issue Jul 19, 2017 · 4 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@zikaari
Copy link

zikaari commented Jul 19, 2017

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Code

Given foo.ts

function foo() { }
export default foo;

transpiles to foo.js as

function foo() { }
exports.default = foo

Why is that? Since consumers of my lib are used to

import foo from 'foo'
foo()

But now they need to

import foo from 'foo'
foo.default()

Expected behavior:
Shouldn't it transpile to

function foo() { }
exports = foo

Similar to what we see around most libs.

@MrKou47
Copy link

MrKou47 commented Jul 19, 2017

It's typescript design. Same issue TypeStrong/ts-loader#583

@zikaari
Copy link
Author

zikaari commented Jul 19, 2017

Some background would be appreciated like what was TS team thinking when they designed this?
As this feels like going against a well known pattern/convention.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jul 19, 2017
@RyanCavanaugh
Copy link
Member

You have a default export and a default import here. If that's not working (foo() rather than foo.default()), then some other tool in your build/run pipeline is broken. TypeScript definitely emits the correct code for this.

@zikaari
Copy link
Author

zikaari commented Jul 19, 2017

Thanks I figured it out, the issue started out of bad d.ts file.

@zikaari zikaari closed this as completed Jul 19, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants