0
votes

Is it possible to export a dictionary discretely? By discretely I mean that each (key, value) will be exported independently of the other values, and will be able to be imported independently.

For example, if I have this object in a module:

const obj = {one: 'two', three: 'four'}

I want to be able to import its values from another file like this:

import {one} from './module'
import {three} from './module'

But obviously, I don't want to explicitly export each key/value manually.

If you export the whole object, the import statements will do what you expect. - Pointy
How so? If I export the object by name, I have to import it by name. If I export it as a default object, I have to do "import default". How can I just import the relevant key and not the whole object? - Winston Smith
"But obviously, I don't want to explicitly export each key/value manually.": That's not how ES modules work. If you want to statically import a name, you must also statically export the name. - jsejcksn
If this is something you are encountering frequently, you can create (or perhaps find a plugin for) a build tool to help you emit source code that meets your requirements (without writing everything directly using your fingers on the keyboard). - jsejcksn