February 2019
Beginner
694 pages
18h 4m
English
When a module file only exports a single item, we can mark this item as a default export. This is accomplished with the default keyword. Consider a module file named lib/Module2.ts, as follows:
export default class Module2Default {
print() {
console.log(`Module2Default.print()`);
}
}
export class Module2NonDefault {
print() {
console.log(`Module2NonDefault.print()`);
}
}
Here, we have marked the Module2Default class as the default export for this module. Note that we can only have a single default export per module, but we are able to export other items within the file using standard export syntax. This can be seen in the second export of the Module2NonDefault class.
If a module has a default export, we can use a simpler ...
Read now
Unlock full access