Import statements & destructuring

PLIQUE Guillaume guillaumeplique at
Thu Oct 15 15:01:20 UTC 2015

Considering the following file exporting a raw object:

/* ./config.js */
const config = {
  api: {
    port: 25,
    host: 'localhost'

export default config;

If another file wants to import this file in order to access the property, it could do it thusly:

import config from './config';

// or else (typically this is what one would expect when importing
some older modules through Babel)
// but I am not entirely sure this would work for real with ES2015
import {api} from './config';

Therefore, wouldn't it be useful to be able to use destructuring
within import statement as you would with objects:

import {api: {host}} from './config';

I guess this does not work for static evaluation reasons but I just
want to be sure this is it or if there are more obvious/profound
reasons concerning modules' system, syntax or philosophy that prevent

More information about the es-discuss mailing list