You can not import * as constants from './constants' because then, if you make a typo, you won't get a ReferenceError, the value will just be undefined. Instead, you must do this:
Of course you can, and then when you start typing constants. your IDE will auto-complete it for you.
You are also missing some other reasons - for example to avoid cyclic imports.
As mentioned, module exports are statically analyzable by design. You can't check that they're strings, but you can check that module Foo exports Bar and Baz with 100% accuracy, assuming its all ES6. Any tool, IDE, linter, whatever, can do the static analysis.
Type systems are useful, but this is not a place where they actually change anything.
you can do that to save a bit of typing, but if you do named exports, you can always import * as foo from './constants' to get an object with all of your constants (and good editors will autocomplete that even without static typing, which is nice).
And in the event you have a lot of constants in one file (probably not a good idea to have too many, but let say you did), you could import them individually and easily find unused ones for scrapping.
9
u/[deleted] May 15 '17
Of course you can, and then when you start typing
constants.your IDE will auto-complete it for you.You are also missing some other reasons - for example to avoid cyclic imports.
You might enjoy reading an article /u/acemarke posted recently - http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/