@zirkelc/typecheck
v1.0.0
Published
Typecheck for Monorepos
Readme
@zirkelc/typecheck
TypeScript type checker for monorepo packages. Runs tsc --noEmit using the TypeScript compiler API and filters out diagnostics from files outside the current package directory.
This solves the problem of internal packages exporting raw .ts files:
Errors in internal dependencies will be reported: When directly exporting TypeScript, type-checking in a dependent package will fail if code in an internal dependency has TypeScript errors. You may find this confusing or problematic in some situations.
Install
pnpm add -D @zirkelc/typecheckUsage
Add a script to your monorepo packages package.json:
{
"scripts": {
"typecheck": "typecheck"
}
}Then run in your monorepo packages:
# Uses tsconfig.json by default
pnpm typecheck
# Use a custom tsconfig
pnpm typecheck --project tsconfig.build.jsonHow it works
- Reads the
tsconfig.json(or--projecttarget) inprocess.cwd() - Creates a
ts.Programand collects all diagnostics viats.getPreEmitDiagnostics() - Filters diagnostics: only keeps errors where the source file is inside the current directory
- Formats remaining errors with colors and code context using
ts.formatDiagnosticsWithColorAndContext() - Exits with code 1 if local errors exist, 0 otherwise
