Sign in
Log inSign up

Typescript : Namespace or static class

nicolasb's photo
nicolasb
·Feb 7, 2018

Hi everyone,

I have this two parts of code which do the same thing.

But for you what is the best ? Using namespace or static class ?

namespace MyMath {  
  const PI: number = 3.14;

 export function calculateCircumference(diameter: number): number {
  return diameter * PI;     
 }
 export function calculateRectangle(width: number, length: number): number {
  return width * length;     
 } 
}
class MyMathClass {  
  PI: number = 3.14;

  static calculateCircumference(diameter: number): number {  
    return diameter * PI;     
  }

  static calculateRectangle(width: number, length: number): number {
    return width * length;     
  } 
}

Let me know !