Exporting and importing modules
Course: Typescript - chapter 11
TypeScript follows the ES6 module system, using **import** and **export** statements to share code between different files. Here’s a brief overview of how this works:
1. Constant exports
Section titled “1. Constant exports”math.ts
export function add(x: number, y: number): number { return x + y;}
export function subtract(x: number, y: number): number { return x - y;}main.ts
import { add } from "./math"
add(1, 2)2. Default exports
Section titled “2. Default exports”export default class Calculator { add(x: number, y: number): number { return x + y; }}calculator.ts
import Calculator from './Calculator';
const calc = new Calculator();console.log(calc.add(10, 5));