I want to create a module with some modules of a js file and do something like this:
import { CONSTANT01, CONSTANT02 } as selectedConstants from './constants'
console.log(selectedConstants) // output => {CONSTANT01: 'CONSTANT01', CONSTANT02: 'CONSTANT02'}
Can this functionality be done?
No, it can't be done like this. Just use a namespace import:
import * as selectedConstants from './constants';
console.log(selectedConstants.CONSTANT01) // output => 'CONSTANT01'
console.log(selectedConstants.CONSTANT02) // output => 'CONSTANT02'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.