Paul Redmond Paul Redmond - 1 year ago 90
TypeScript Question

TypeScript - Use modules or classes with unit testing in mind?

Which strategy of content architecture is best with unit testing in mind in TypeScript? Creating modules or classes?


// Exported method

var x = moduleX.method1();
// Public method

Answer Source

best with unit testing in mind in TypeScript

If you have a function that doesn't depend on local state in a class .... then it should just be a function. No need to new SomeClass().foo() when you can foo()

Here you can use namespaces to offer a nice consolidation of different function into a single object : and you get something like

Be warned that I would prefer you just make a javascript module instead of a namespace :

Most importantly have fun

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download