Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have been testing typescript with node, all was going well until i tried splitting these out.

Am I forced to use modules ?

I have 2 files, app.ts which has a reference path to the hellofile.tst

/// <reference path="hellofile.ts" />
var testme = new Hello()
console.log(testme.testMe());

and the hellofile.ts which contains

class Hello {
    testMe():string {
        return "hello";
    }
}

Now running the program (i am using webstorm), I get the following error.

/usr/local/bin/node app.js

/

Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2
var testme = new Hello();
                 ^
ReferenceError: Hello is not defined
    at Object.<anonymous> (/Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Process finished with exit code 8

Any help or ideas really appreciated

thanks

share|improve this question
    
Relevant similar question and answer: stackoverflow.com/questions/12930049/… – jfriend00 Mar 31 '15 at 21:00
up vote 2 down vote accepted

You don't have to use modules. You can compile with --out flag

But external modules with commonjs is highly recommended if targeting nodejs : http://m.youtube.com/watch?v=KDrWLMUY0R0

share|improve this answer
    
Great, and nice videos. Thanks. – Martin Apr 1 '15 at 17:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.