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
- Inputs. Using a component checks the values you pass against its
@inputtypes: a missing input, an unknown one, or a wrong type is an error on the tag. - Holes and attributes. Every
{{ }}and[attr]expression is type-checked against the inputs, script variables and imports it can see. - Control flow.
@ifnarrows types likeif, and@fortypes the row variable from the list. - Events. In
(click)="…",$eventhas the right event type, such asMouseEvent. - Rendering by name.
render('components/pill', { text })fromclarusjs/viewsis checked against the view's inputs, through the generated.clarusjs/views.d.ts. - Scripts and data. An island's script, and data brought in with
@import, are ordinary TypeScript.
{{-- 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 checkHow 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.