Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

New rule: no-default-export #1182

Closed
adidahiya opened this issue Apr 29, 2016 · 7 comments · Fixed by #1209
Closed

New rule: no-default-export #1182

adidahiya opened this issue Apr 29, 2016 · 7 comments · Fixed by #1209

Comments

@adidahiya
Copy link
Contributor

adidahiya commented Apr 29, 2016

In my experience, default exports are not a great practice, especially anonymous ones. I think you should always name the things you are exporting. Also, default exports allow for subtle mistakes after refactoring. With default exports, you could change the semantics of a component but it might be imported elsewhere with a name suggesting its old semantic meaning.

// app.ts
import ActionPopover from "./action";
// action.ts
export default class ActionMenu {
    ...
}
// oops, we just renamed this from popover -> menu but our consumer had no idea!
@patsissons
Copy link
Contributor

If nobody is interesting in taking this one, I would love to get this in the code base today.

@adidahiya
Copy link
Contributor Author

go for it @patsissons!

@adidahiya adidahiya modified the milestones: 3.11, TSLint v3.11 Jun 9, 2016
barbuza added a commit to barbuza/typescript-webpack-preact-experiment that referenced this issue Nov 1, 2016
@adidahiya
Copy link
Contributor Author

relevant to those on this thread: #2117

@Jamesernator
Copy link

I'm not really convinced by the arguments here.

Typically when using export default you have the name of the file being the same (within project conventions) as the thing being exported e.g.:

import fizzBuzz from "./fizzBuzz"
// or depending on convention in the project
import fizzBuzz from "./fizz-buzz"

Following that convention you'll never hit a case where the semantic meaning of a name is different from the import-ed name as you have to refer to exactly the file that contains that certain object, if the export changes then so must the filename.

@adidahiya
Copy link
Contributor Author

if the export changes then so must the filename

but we don't have a lint rule to enforce that :)

@theKashey
Copy link

This is not a issue for a typeless ES6, it should not be a issue for TS.
If you are replacing ActionPopover by ActionMenu, then, well, problem is in you ;)

@anurbol
Copy link

anurbol commented Jul 19, 2018

Sorry for necro-posting. I found this rule to be very useful to enforce one style of exporting things (especially classes) across an app.

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

Successfully merging a pull request may close this issue.

5 participants