This project is read-only.

export property on module

Topics: General, Language Specification
Apr 30, 2014 at 10:57 PM
Is it possible to define an export property on a module? If do, what is the syntax? At the moment I'm resorting to using a class with only static members, but it seems like I should be using module rather than class for this.
May 1, 2014 at 7:53 AM
Did you mean something like this
module foo {
    export var bar = "barbar";

console.log(; // barbar
Out of curiosity, why don't you like using a class?
May 1, 2014 at 10:20 AM
No, I mean a property as in:
class foo
     public static get bar() {
         return "barbar";
I use a class for this at the moment, using the same syntax as above but that leaves me with a redundant constructor. Achieving the real equivalent of a static class in TypeScript seems to be a module with the 'public' functions being exported, e.g.:
module foo
    export function getBar() {
        return "barbar";
But as far as I can tell, while you can export functions from a module (as above), you cannot export a property in the same way you can with a class.
May 1, 2014 at 7:11 PM
Property getters in modules currently aren't supported.

A reasonably type-safe workaround is this:
module M {
    export declare var t: string;
    Object.defineProperty(M, "t", {
        get(): typeof t { return "hello"; } 

console.log(M.t); // 'hello'