1

I'm pretty new to Javascript, NodeJS and --obviously-- TypeScript. I'd like to experiment with the compiler services in src/services (Windows) to provide intellisense, etc. for an editor.

As far as I can tell, I need to be able to require the TypeScript services code in a NodeJS server and communicate with that from the editor. I couldn't find any NodeJS-specific TypeScript services code, so I think I'd have to compile the services code with --module amd to make it available to NodeJS via RequireJS.

If the above is correct, my attempts to compile the services code with --module amd yield exactly the same results as using the default module kind (see below).

$ tsc.cmd --module amd --out amd.js .\languageService.ts
$ tsc.cmd --out comm.js .\languageService.ts
$ diff.exe .\amd.js .\comm.js
$
guillermooo
  • 7,915
  • 15
  • 55
  • 58
  • I created a video tutorial on internal vs. external modules to clarify confusions : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1 – basarat Sep 27 '13 at 03:44
  • If your goal is editor support for TS, check out [typescript-tools](https://github.com/clausreinke/typescript-tools) – claus Sep 27 '13 at 09:45

2 Answers2

2

This is admittedly confusing, but the code in languageService.ts isn't in a 'module' in the sense of AMD/RequireJS's definition of 'module'.

The spec refers to things inside a module block as "internal modules". That's what you're seeing in languageService.ts. You can think of them more like containers or singletons that expose a top-level name (looking at the code gen for a simple internal module clarifies this quite a bit). You consume these like regular top-level objects without any module loader at all.

Producing external modules (as named by the spec) for require is done by putting the export directive on a top-level declaration in a .ts file (see spec section 9.2.1). There are some samples (e.g. imageboard) available for download that do this if you're interested.

Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235
  • 1
    Just going to language-lawyer myself: Internal modules introduce a name in their parent scope, not at the top-level. – Ryan Cavanaugh Oct 02 '12 at 21:45
  • related TS issues: https://typescript.codeplex.com/workitem/521 https://typescript.codeplex.com/workitem/534 https://typescript.codeplex.com/workitem/97 – claus Sep 27 '13 at 09:46
1

You have to have your modules defined as export module, not your module and then compile it with --m amd or --module amd.

Took me few hours to realize :)

Nikita Silverstruk
  • 1,097
  • 1
  • 20
  • 42
David Bohunek
  • 3,181
  • 1
  • 21
  • 26
  • Welcome to StackOverflow. BTW, it looks like you're looking for the backticks instead of the single quotes. – Translunar Sep 26 '13 at 19:58