r/javascript • • May 15 '17

Don't Overcomplicate Javascript #0

https://bits.ristic.io/dont-overcomplicate-javascript-0
35 Upvotes

34 comments sorted by

View all comments

Show parent comments

0

u/[deleted] May 15 '17

[deleted]

2

u/siegfryd May 16 '17

ES6 module exports are statically analysable, so they should be safe regardless of whether you're using a type checker or not.

0

u/[deleted] May 16 '17

[deleted]

1

u/phoenixmatrix May 17 '17

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.

0

u/[deleted] May 17 '17

[deleted]

1

u/phoenixmatrix May 17 '17

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.