Skip to content

NAMESPACE

Justin Lazaro edited this page Dec 22, 2018 · 1 revision

app.ts

/// <reference path="namespace-CircleMath.ts" />
/// <reference path="namespace-RectangleMath.ts" />

import CircleMath = MyMath.Circle;

const PI = 2.99;
console.log(CircleMath.calculateCircumfrence(2));
console.log(MyMath.calculateRectrangle(2, 6));
console.log(PI);

// tsc namesmodules.ts --outFile namesmodules.js

CircleMath.ts

namespace MyMath {
  export namespace Circle {
    const PI = 3.14;

    export function calculateCircumfrence(diameter: number) {
      return diameter * PI;
    }
  }
}

RectangleMath.ts

namespace MyMath {
  export function calculateRectrangle(width: number, lenght: number) {
    return width * lenght;
  }
}
Clone this wiki locally