1

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?

1 Answer 1

6

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.