Plugin Development
For plugin authors β people writing new ttsc plugins. If you just want to use existing plugins like typia or @ttsc/lint, you donβt need this section. Go to TTSC Β· Using plugins instead.
This chapter is organized in three tiers:
Concepts
Background you need before authoring.
- Plugin protocol β the npm package contract and binary subcommands every
ttscplugin implements. - AST & Checker β how TypeScript-Go exposes the AST and Checker to Go plugins.
Authoring
The build-and-publish path.
- Getting started β smallest useful transform plugin, end to end.
- Recipes β focused patterns you can copy.
- Testing β Go unit tests + end-to-end
ttscfixtures. - Publishing β npm package shape and pre-publish checks.
- Local development β
go.work,gopls,go test, pnpm notes.
Reference
Deeper material β read as needed.
- Architecture β source-plugin build cache and Go toolchain resolution.
- Reference plugin tour β guided walkthrough of
banner,strip,paths, andlint, by difficulty. - Pitfalls β common first-hour failures.
- Workspace release β repository build, test, and release flow.
How a plugin works, in one paragraph
A ttsc plugin is an npm package with two halves: a JS descriptor that lives in the consumerβs node_modules and tells ttsc what the plugin does, and a Go transform that holds the actual logic. The Go transform reads the TypeScript-Go AST, queries the Checker, then either reports diagnostics or rewrites emit. It compiles once into a binary the first time itβs used, and the binary is cached. Plugins run everywhere ttsc runs β CLI, ttsx, ttscserver, every @ttsc/unplugin bundler adapter. One contract, one config (tsconfig.jsonβs compilerOptions.plugins).
Real code to read
Each first-party plugin is small enough to read end-to-end. Start with banner.
packages/bannerβ smallest transform plugin.packages/stripβ source transform with statement removal.packages/pathsβ transform with tsconfig parsing and Program-backed path resolution.packages/lintβ diagnostics plugin with Program/Checker access.
Test fixtures that bootstrap a Program for you:
tests/projects/go-source-plugin-checkerβ minimal Program/Checker setup.tests/projects/go-source-plugin-propertiesβ AST traversal fixture.
Status
v1 protocol, still moving. Donβt publish ttsc as a peer dependency yet β treat it as a build-time-only dependency.
Requirements
- Node.js 18+
- Go 1.22+ (for
go test/go vet) - A consumer test fixture with
ttscand@typescript/native-previewinstalled.