astro check is the Astro CLI command that type-checks your whole project, including the frontmatter and template expressions in .astro files that plain tsc can’t read. Run npx astro check; it reports errors, warnings and hints, and exits with a non-zero code when it finds errors, so you can use it to fail a CI build.
Key Takeaways
- Needs
@astrojs/checkandtypescriptas dev dependencies; Astro offers to install them the first time.- Runs
astro syncfirst, so content collection andastro:envtypes are current.--watchre-checks on save;--minimumFailingSeverity warningmakes warnings fail the run.- In Astro 7.4,
astro checkrefuses to run on TypeScript 7; stay on TypeScript 6 for now.
Set it up
# terminal
npm install -D @astrojs/check typescript
npx astro check
If the packages are missing, astro check asks to install them for you. Add a script so everyone runs the same thing:
// package.json
{
"scripts": {
"check": "astro check",
"build": "astro check && astro build"
}
}
Chaining it before astro build stops a broken commit from deploying.
What it catches
astro check runs the Astro language server’s diagnostics, the same ones your editor shows with the Astro extension, across every file in your project:
- Props passed to a component that don’t match its
Propsinterface - Wrong types in frontmatter, such as calling a string method on a possibly
undefinedvalue - Content collection fields used with the wrong type, based on your schema
- Errors in
.tsfiles and in React, Vue, Svelte or Solid components included by your tsconfig
Each diagnostic shows the file, line and column with the TypeScript message, and the run ends with a summary:
Result (42 files):
- 1 error
- 0 warnings
- 2 hints
It doesn’t check CSS, HTML validity or accessibility. For those, use a linter or a browser audit.
Flags worth knowing
| Flag | What it does |
|---|---|
--watch |
Keeps running and re-checks when files change |
--root <path> |
Checks a project in another folder |
--tsconfig <path> |
Uses a specific tsconfig file |
--minimumSeverity <level> |
Hides diagnostics below error, warning or hint (default) |
--minimumFailingSeverity <level> |
Sets which level causes a non-zero exit (default error) |
--preserveWatchOutput |
Doesn’t clear the terminal between watch runs |
--noSync |
Skips the astro sync step |
For a stricter CI gate:
# terminal
npx astro check --minimumFailingSeverity warning
Use --noSync only when a previous step already ran astro sync or astro build, because stale generated types cause false errors.
The TypeScript 7 caveat
Astro 7.4 checks your TypeScript version first. With TypeScript 7.0 installed it stops with this message:
astro check does not currently support TypeScript 7.0. To continue using astro check, install TypeScript 6 instead.
The same message says astro check will be deprecated in a future release, and points to experimental support for TypeScript 7.1+ through @astrojs/ts-content-mapper. Until that’s stable, pin TypeScript 6:
# terminal
npm install -D typescript@6
In CI
# .github/workflows/check.yml
name: Check
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npx astro check
Astro 7 needs Node.js 22.23.4 or newer, which node-version: 22 resolves to. Komal themes are TypeScript Astro 7 projects, so astro check is the quickest way to see whether your edits to a theme from the catalog broke a component’s props. Our folder structure docs show where the tsconfig sits. See every Astro CLI command for the rest of the CLI, astro sync for the type generation step, and Astro’s type checking guide for editor setup.
FAQ
What is the difference between astro check and tsc?
tsc only understands .ts and .tsx files. astro check also checks .astro components, including frontmatter and expressions in the template, and runs astro sync first so generated types exist.
Does astro build run astro check?
No. astro build compiles without type-checking. Add astro check && before astro build in your build script if you want type errors to block deploys.
Why does astro check fail with TypeScript 7?
Astro 7.4’s astro check doesn’t support TypeScript 7.0 yet and stops with an error. Install TypeScript 6 with npm install -D typescript@6.
Can astro check run in watch mode?
Yes. npx astro check --watch re-runs diagnostics as you save. Run it alongside astro dev, which keeps generated types up to date.