I'm new to TypeScript, and the more I read about modules and namespaces, the more I get confused. Should I go with modules? Should I go with namespaces? Do I use both? help!
I have javascript files (.js) that I am trying to convert to TypeScript. There is one .js file with some common functions and one .js file with some functions specific to filters.
Now I would like to organize this a bit more with TypeScript, as I would normally do with C #.
Is this the right use or how to organize it?
I do not use the module, right? (How?)
Company.ts
namespace Company {
Company.Project.ts
namespace Company.Project { import Company; // like this? let myVar : string = "something"; export function handyGeneralFunction1(foo, bar) { // ... } export function handyGeneralFunction2(foo, bar, foo, bar) { // ... doInternalCalc(); // ... } export function handyGeneralFunction3() { // ... } function doInternalCalc() { // ... } }
Company.Project.Filter.ts
namespace Company.Project.Filter { import Project = Company.Project; // like this? export function initializeFilter() { // ... initMetadata(); // ... } function initMetadata() { // ... Project.handyGeneralFunction3(); let helper : FilterHelper = new FilterHelper("aaaa,bbbb"); let res:string[] = helper.parseData(); } function foo() { // ... let x :string = Project.myVar + " else"; // can I use myVar here? } // a class in the namespace export class FilterHelper { data: string; constructor(theData: string) { this.data = theData; } parseData() : string[] { // ... return new Array<string>(); } } }
source share