18

Are there any docs / examples of writing a Typescript plugin?


For the last time I am very inspired with the idea of bringing Typescript into my projects. However, currently I see this is not possible because of my failed attempts to find any docs about writing a Typescript plugin. I need this plugin for combining classes metadata during compilation and then generating an asset. It was not that easy but I've already written such for babel and now I am interested if it is possible to do the same with Typescript.

James Akwuh
  • 2,169
  • 1
  • 23
  • 25
  • 1
    You can download https://github.com/microsoft/typescript, include it into your project and via Compiler API or TypeScript Language Service work with TypeScripts codes. You can write your own compiler if you need. Basics are described in wiki https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API and https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API – Misaz Nov 10 '16 at 06:09
  • @Misaz yes, that's what I was looking for! Thanks a lot! Could you please post your comment as the answer so I will accept it and help other developers to find these useful links? – James Akwuh Nov 10 '16 at 14:39

2 Answers2

14

You can download https://github.com/microsoft/typescript or via npm.

npm install typescript

Then include it into your project and via Compiler API or TypeScript Language Service work with TypeScripts codes. You can write your own compiler if you need. Basics are described on the wiki.

https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API

Misaz
  • 3,694
  • 2
  • 26
  • 42
7

There are now some docs available for language service plugins at:

https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin

But note that the language service is not called by the tsc command, but only from apps (typically IDEs / editors I believe).

The https://github.com/cevek/ttypescript project patches tsc to support transformers which may be a route for people who require support in the tsc command too.

robd
  • 9,646
  • 5
  • 40
  • 59