Lightweight
Lightweight

Reputation: 504

How to structure TypeScript

I have been charged with investigating whether or not to use Type Script for our product and one of my primary objectives is that the new script generated from Type Script should have the same signatures as the old JS

Our existing structure is slightly namespaced in that we have a base Function/namespace and other modules in our app hang off the base namespace. The issue is that the base namespace also has functions hanging off of it

CompanyName.doSomething = function() {}

CompanyName.module = { doSomethingElse: function() {} }

So idealy in TS, id have a module named CompanyName and then have other class's exist within that module, but what do i do with the functions that belong directly to that root namespace, how do i structure this in TypeScript?

Upvotes: 1

Views: 900

Answers (1)

Fenton
Fenton

Reputation: 250812

Here is an example of nesting functions and classes inside of a module...

module CompanyName {
    export function doSomething () {
        return 1;
    }

    export class ModuleName {
        static doSomethingElse() {
            return 2;
        }
    }
}

var a = CompanyName.doSomething();
var b = CompanyName.ModuleName.doSomethingElse();

alert(a + ' ' + b);

Upvotes: 6

Related Questions