October 2017
Intermediate to advanced
280 pages
6h 50m
English
If a given module defines an export, which would quite likely be used by any of its consumer modules, we can take advantage of the default export syntax:
// ch4/modules/math3.ts
export default function cube(x) {
return Math.pow(x, 3);
};
export function square(x) {
return Math.pow(x, 2);
};
In order to consume this module, we can use the following app.ts file:
// ch4/modules/app3.ts import cube from './math3'; console.log(cube(3)); // 27
Alternatively, if we want to import the default export, together with additional exports, we can use this:
// ch4/modules/app4.ts
import cube, { square } from './math3';
console.log(square(2)); // 4
console.log(cube(3)); // 27
In general, the default export is nothing more than an named ...
Read now
Unlock full access