That’s all we can say right now.
It is recommended that when a name is being used from a module that is imported as a full namespace, the name should be exported from the imported module. That is, whenever we import a module using a wildcard (*
) like this:
import * as someModuleName from './path/to/the/module'
And use its function or variable or class like this:
const data = someModuleName.getData()
it is important to make sure that the name that is being used (getData
in the above example) should be exported from the referenced module; otherwise, it will give unexpected values like undefined
for variables and it might throw TypeError
as well (for example when calling a function).
// <!-- config.js -->
export const KEYS = 'secret'
const TTY = 2030
const isValid = (a) => a < TTY
// <!-- index.js -->
import * as config from './config.js'
console.log(config.TTY) // undefined
console.log(config.isValid(2000)) // TypeError : isValid is not a function.
// <!-- config.js -->
export const KEYS = 'secret'
export const TTY = 2030
export const isValid = (a) => a < TTY
// <!-- index.js -->
import * as config from './config.js'
console.log(config.TTY) // 2030
console.log(config.isValid(2000)) // true