Are there any docs / examples of writing a Typescript plugin?
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.