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

Improve readability of default exports #7407

Closed
kbtz opened this issue Mar 6, 2016 · 4 comments
Closed

Improve readability of default exports #7407

kbtz opened this issue Mar 6, 2016 · 4 comments

Comments

@kbtz
Copy link

kbtz commented Mar 6, 2016

I'm unable to export default modules/namespaces like this:

export default namespace Utils { // throws  error TS1005: ';' expected
...

Not sure if its related to #3792, but that isn't actually my issue...
Since I can't export default the namespace directly, I would like to convention that default exports should be placed in a separate statement and always put in the first lines of the file:

export default Utils

import * as Foo from "foo"
// ...
import {Bar, Baz} from "bar"

let fooIt = Foo.Factory.SpecialFoo.Create
// ...

namespace Utils {
  // ...
}

IMO it would improve readability and make it easier to understand how to consume that file/module.

Despite the fact that the compiler seems to understand that I'm exporting the Utils namespace, the transpiled code does not associate the export statement and my internal module, causing the default export to be undefined at run time.

Would be nice to get export default transpiled to the of the file or declare the module container earlier, so I can export it wherever I want.

If #3792 gets fixed I can just convention that the default module should always come first, and keep my default export always on sight. So this is issue is more like a suggestion I suppose...

Typescript Version 1.9.0-dev.20160220

@RyanCavanaugh
Copy link
Member

Would be nice to get export default transpiled to the of the file

I'm not 100% clear on what's being reported. I've added export default namespace Utils { to #3792; is there another bug here assuming that one gets fixed?

@kbtz
Copy link
Author

kbtz commented Mar 7, 2016

@RyanCavanaugh More an improvement than a bug fix...

For example, the compiler allows me to reference Foo on export default Foo and declare it afterwards, which is nice!

However the transpiled code uses Foo before var Foo; is declared as shown here

What I'm asking is, since the compiler is already capable of recognizing Foo ahead of time, it should also declare var Foo; accordingly.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 7, 2016

this looks like a duplicate of #4101

@kbtz
Copy link
Author

kbtz commented Mar 7, 2016

Indeed @mhegazy, thank you!

@kbtz kbtz closed this as completed Mar 7, 2016
@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
None yet
Projects
None yet
Development

No branches or pull requests

3 participants