Hey, thanks for the reply! You pointed me in the right direction.
I’ve done some more testing and it turns out that you can also import the default export together with all the named exports using import * as Alias from './file';
HOWEVER, it seems that to then be able to access it, you have to use Alias.default
. In other words, you can’t access it via its name/identifier (in this example myDefaultExport
).
This is what led to my confusion, as in the associated lesson and exercises, we had only covered accessing the object that was exported using export default myDefaultExport
(and then imported) by reference to its identifier (in this example myDefaultExport
).
It seems that when you import the default export separately (using import myDefaultExport from './file'
), then you have to access it (and its properties) via its identifier e.g.
// based on the example given in the original FAQ model answer
console.log(myDefaultExport.name); // prints "default export"
console.log(default.name); // throws an error
However, when you import the default export together with all the named exports under an “umbrella” alias (using import * as Alias from './file'
), then it seems that you have to access it (and its properties) via the keyword default
as a property of Alias
e.g.
// based on the example given in the original FAQ model answer
console.log(Alias.default.name); // prints "default export"
console.log(Alias.myDefaultExport.name); // throws an error
So in the end it seems that the model answer is correct, and I was wrong. However, I hope that by questioning this, and adding this explanation, I may have provided some clarification to anyone else confused by the same thing…
…although, this is only what I’ve deduced myself based on playing around. If anyone else can confirm this, that would be great!