0

Typescript modules

Hi,

I am trying to learn Typescript, and have difficulties to find good documentation for a complete beginner.

I would like to put my code into modules, normally one class per module. I thought  it would be this simple:

I create two files, abc.ts and def.ts,  each file defines a class, and class Def will use class Abc.

File abc:

module abc {
    export class Abc {
       name: string;
       constructor(name: string) {
          this.name = name;
       }
        getName= function() {
           return this.name;
        }
    }
}

File def.ts

import a = require("abc");
module def {
    export class Def {
       name: string;
       myAbc:a.Abc;
       constructor(name: string) {
          this.myAbc= new a.Abc("foo");
          this.name = this.myAbc.getName();
       }
       getName= function() {
          return this.name;
       }
    }
}

However, Webstorm (7.0) will not find the file abc.ts when def.ts is compiled They are both in the same directory.

I get the following errors:

myDir/js/def.ts(2,1): error TS2071: Unable to resolve external module '"abc"'.

myDir/js/def.ts(2,1): error TS2072: Module cannot be aliased to a non-module type.

error TS5037: Cannot compile external modules unless the '--module' flag is provided.

I don't understand the second error code TS2072

The last error code seems to give a hint: How do I set the module flag?

I have tried adding /// <reference path="./abc.ts" /> at the top of file def.ts, with no improvement.

Any help is welcome (also links to good newbie documentations)!

2 comments

Please sign in to leave a comment.