This project is read-only.

How do I use the language services in a TypeScript commonJS node project?

Topics: General
Apr 24, 2014 at 2:48 PM
I have dabbled a little in using the precompiled typescriptServices.js (hacky with require.js).

Now I'd like to have a go at some more detailed services but then I'd want to leverage the compiler checking

We write TypeScript in the node.js style, with external modules, as it works great with code coming from npm (and defs from DT). But the compiler is written in internal module style.

So how do I interface my external module code with the internal module compiler code?

I tried a few thing, but it is all a bit messy. I have a choice between the npm-published code (lacks services), but also the precompiled typescriptServices.js and the raw source from this repos.
Apr 25, 2014 at 8:46 PM
The reason why nothing is exported is mainly related to support. We did not want to commit to a public API surface area yet. This applies to the compiler and the language service as well; and since the Language Service file is not runnable from the command line, publishing it through npm is a not of much use. Once we are ready to commit to the API we I expect us to publish both in the npm package with the correct exports. Using the raw LKG drop from the enlistment should get you the latest, there are always chances for things to change. My advice is to stick to the ILanguageService interface, this is the one most LS users depend on, and the most stable, I do not expect it to change much overtime, may be add new features, or change some parameter types. using the Compiler semantic model (decls, symbols, etc..) directly would be riskier, I expect that to keep changing for a while.
Apr 25, 2014 at 9:02 PM
Makes sense, but I can easily vendor the code I use in my project so I just pick something from the repo.

But note the code is all internal module code now.

Is there a recommended way to use it typed in a project that uses external module style (eg: node/amd code via import/require?
Apr 25, 2014 at 9:15 PM
The easiest way would be to use typescriptServices.d.ts that is generated as part of the local build. append "export = TypeScript", now you can import that as an external module. on the consuming side, you need to add the export= TypeScript on node as well. hope that helps.
Apr 25, 2014 at 10:01 PM
This was pretty easy. I did hit a small glitch with some types that become private because of the single export.

Can be hacked also, but here is a ticket for it: