ES6 Modules - with Import with a Common Alias

If I understand correctly, then importing ES6 modules does not allow:

import { background, border, foreground } as colors from "./colors";

use(colors.background);
use(colors.border);
use(colors.foreground);

Cm

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/import

Is there any explanation why?

I like the idea of โ€‹โ€‹explicitly listing the things I want to import. Therefore, I do not like import * as colors from "./colors";it because he does not understand what I use.

This, on the other hand, too long-winded for me import { background as backgroundColor, border as borderColor, foreground as foregroundColor } from "./colors";.

Any idea how to be explicit and not overly detailed?

+4
source share

Source: https://habr.com/ru/post/1658605/


All Articles