r/javascript • • Aug 27 '18

`export default` considered harmful

https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
32 Upvotes

43 comments sorted by

View all comments

2

u/kowdermesiter Aug 27 '18

If you refactor Foo in foo.ts it will not rename it in bar.ts.

Yes it will if you use a sane IDE like VSCode

If you end up needing to export more stuff from foo.ts (which is what many of your files will have) then you have to juggle the import syntax.

Oh the horrors... it was a single variable, now it might be 2 or god... three.

If a module has default exports then I don't need IntelliSense, it's a single damn module

You don't get typos like one dev doing import Foo from "./foo"; and another doing import foo from "./foo";

So yeah, that takes a few second to discover. I doubt that this is a problem since you start with the import and using the imported variable will come from the autocomplete.

Keep using defaults folks when it makes sense, like a module only contains a single class / object / variable.

1

u/[deleted] Aug 27 '18

Your comment doesn't make much of a case for defaults, other than characterising the objections as whining. I am curious to know why some people prefer them. I am aware of the airbnb decision but I am not completely convinced. In fact, I don't understand why they added this quirky and seemingly unnecessary extra to the specification.

1

u/kowdermesiter Aug 27 '18 edited Aug 27 '18

It IS whining or bikeshedding to say the least.

Thanks for the AirBnB link, I missed it.

I am curious to know why some people prefer them.

Like I said, if you have a single thing in a file, then defaults are perfectly fine.

I'm using it right now: https://imgur.com/a/20Wutgv

It's just nice that I don't have to use { Stuff } to import a class when it's all that a file contains.

MDN says the same thing:

https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#Using_the_default_export