r/javascript • u/JavaScriptWorks • Nov 29 '17
Why we have banned default exports in JavaScript and you should do the same
https://javascript.works-hub.com/blog/Why-we-have-banned-default-exports-in-JavaScript-and-you-should-do-the-same?utm_source=eliott&utm_medium=reddit&utm_campaign=content3
u/hirako2000 Nov 30 '17
If default exports work for some teams.. not sure why we should all do the same. but thanks for sharing...
2
3
u/beaverusiv Nov 30 '17
I had not used default exports before (as I just inherently knew the benefits of named ones) and stepping into a project that has everything exported default instead of named brought me to the same conclusion - never use default.
1
u/burtgummer45 Nov 30 '17
We better get to banning this also.
import { rightName as wrongName } from module8
u/kingdaro .find(meaning => of('life')) // eslint-disable-line Nov 30 '17
I don't agree. There are cases where different files may have similarly-named exports being imported into one file. Cases like this are probably what
as newNameis meant for. Example:import { combineReducers } from 'redux' import { reducer as userReducer } from 'modules/user' import { reducer as authReducer } from 'modules/auth' import { reducer as chatReducer } from 'modules/chat' export const rootReducer = combineReducers({ user: userReducer, auth: authReducer, chat: chatReducer, })A somewhat contrived example, and a little boilerplatey, but you get the idea.
7
u/burtgummer45 Nov 30 '17
Well I don't agree either, I think the original post is dumb, I was making a point that named exports can be whatever name you want.
3
0
Nov 30 '17
[deleted]
1
u/kingdaro .find(meaning => of('life')) // eslint-disable-line Nov 30 '17
There are better ways of handling this specific case; it's only an example. OP wasn't being serious anyway.
6
u/kingdaro .find(meaning => of('life')) // eslint-disable-line Nov 30 '17
The title seems a little dogmatic, but I definitely agree, especially in relation to tooling with TypeScript. Project-wide renames sometimes work with default exports, but not as consistently as named exports. Relevant link