Guide › Tooling

Type checking

clarusjs check type-checks your templates with your project's own TypeScript, and reports errors where you wrote them: file.tscl:line:col.

Set up

Install TypeScript in your project (clarusjs uses whichever version you have), then add a script:

pnpm add -D typescript
// package.json
"scripts": { "check": "clarusjs check" }

Then run it:

pnpm run check

If your project has a tsconfig.json, its settings are used; otherwise strict defaults with browser types.

What it checks

{{-- src/pages/index.tscl --}}
@import { nav } from '../nav'
@for (item of nav) { <a [href]="item.hrfe">{{ item.title }}</a> }
<code>$ pnpm check
src/pages/index.tscl:2:38 error TS2339: Property 'hrfe' does not exist on type '{ title: string; href: string; }'.

1 error</code>

In CI

The command exits with 1 when there are errors, so it fails a CI job on its own. Add --json to get the diagnostics (file, line, column, code, message) for other tools. This site checks itself in CI the same way.

- run: pnpm check

How it works

Each .tscl file is turned into a TypeScript file that means the same thing (@if becomes if, a component tag becomes an object typed as its inputs) and is never run. TypeScript checks those files, and each error is mapped back to the template. They are written to .clarusjs/: keep that folder out of version control.