svelte-check-native
v1.9.1
Published
Fast CLI type-checker for Svelte 4 and Svelte 5 projects. Drop-in replacement for svelte-check, written in Rust, powered by tsgo.
Maintainers
Readme
Blazing fast CLI type-checker for Svelte projects. Drop-in replacement for svelte-check — compatible flags, byte-identical diagnostics, same exit codes. Single Rust binary, powered by TypeScript 7's native tsc. Built for AI agents, CI/CD, and pre-commit hooks that actually stay enabled.
Not an LSP, CSS linter, or formatter.
Speed
Measured on a SvelteKit + TypeScript monorepo with
1359 .svelte files (Svelte 5 runes), M1 Pro 8C, mean of 2 runs each:
svelte-check-native --tsconfig tsconfig.json --diagnostic-sources 'ts,svelte'
tool cold warm dirty speedup errors/warnings/problems
──────────────────────────────────────────────────────────────────────────────────────
svelte-check-native 2.5s 0.2s 0.9s 40x 0/49/17
svelte-check 40.0s 41.0s 41.6s 1.0x 0/49/17
svelte-check --tsgo 18.3s 18.6s 17.9s 2.9x 1/49/18
svelte-check-rs 12.2s 5.5 4.4s 7.5x 732/44/261Diagnostic counts match svelte-check with same flags.
Install
npm i -D svelte-check-native typescript@^7.0.0TypeScript 7 provides the native tsc binary required at check time;
it is never imported at runtime. @typescript/native-preview (tsgo,
the nightly channel) works too, as the fallback when typescript 7+
isn't installed — so you can keep typescript@6 for your own
toolchain and check with tsgo. TypeScript 6 and below is never used
as the check engine.
Use
npx svelte-check-native --workspace .Or add it to package.json:
{
"scripts": {
"check": "svelte-check-native --workspace ."
}
}Same flags as svelte-check. See npx svelte-check-native --help.
How it works
Single Rust binary. Each .svelte file flows through a handful of
crates in one process:
| Crate | What it does |
| ----------------- | ----------------------------------------------------------------------------------------------- |
| parser | Parses .svelte source into a Svelte-5 AST (script + template). |
| analyze | Semantic passes — runes, prop shapes, events, bindings, scope — feeding emit and lint. |
| emit | Generates the .svelte.ts overlay TypeScript will type-check. Imports rewritten so tsc lands on it. |
| svn-lint | Native Rust port of svelte/compiler's warning pass. Covers all known codes; no subprocess. |
| svelte-compiler | Fallback bridge to the user's svelte/compiler over a persistent bun/node worker pool. |
| typecheck | Owns the TypeScript overlay tsconfig + the tsbuildinfo cache; invokes tsc; maps diagnostics back. |
| core | Shared types (spans, diagnostics, position maps) + the canonical TsConfig struct. |
| cli | Entrypoint. Flag parsing, file discovery, output formatting, exit codes. |
Flags
Every flag not listed below behaves the same as svelte-check.
New flags
--svelte-warnings <mode> How to source Svelte compiler warnings:
native | bridge
native: rust port faster
bridge: js bridge same as svelte-check, slower by 1.5-2s
--timings Phase-by-phase wall-clock breakdown
--debug-paths Print resolved binaries, exit
--tsgo-version Print tsgo version, exit
--tsgo-diagnostics Print tsgo's perf/memory stats after the run
--emit-ts Print generated TypeScript per file, exitNot supported
--watch/--preserveWatchOutput— usewatchexecor your editor's file watcher externally.--no-tsconfig— errors out. A tsconfig is required.--tsgo— always on. TypeScript 7's nativetscis used.--diagnostic-sources css— accepted but no-op (a CSS language service isn't bundled). Roadmap below.
Run svelte-check-native --help for the full list.
Output defaults to machine when run from Claude Code (CLAUDECODE=1),
as upstream's does.
Environment variables
TSGO_BIN— override discovery; accepts an absolute path to a platform-nativetsgo/tscbinary or JS wrapper. Useful when neither engine package is innode_modules(e.g. a monorepo where TypeScript lives elsewhere).SVN_BRIDGE_WORKERS— number ofsvelte/compilerworker subprocesses. Defaultcores/2, capped at 8; tracks the perf-core count on Apple Silicon. Override if you hit IPC contention on very large core counts.CLAUDECODE=1— makesmachinethe default output format.NO_COLOR/FORCE_COLOR— turn colour off / on, as for upstream.
Android (Termux)
svelte-check-native's linux-arm64 binary is static, so it installs
and runs on Android too. TypeScript 7 doesn't publish an Android
build, so npm skips its native compiler there. Its linux-arm64 build
runs fine on Android; install it explicitly:
npm i -D --force @typescript/typescript-linux-arm64@<your typescript version>Or point TSGO_BIN at any Linux arm64 tsc/tsgo binary.
Exit codes
0— no errors (and no warnings if--fail-on-warnings)1— errors detected (or warnings with--fail-on-warnings), or the TypeScript compiler did not complete (killed, or exited without a diagnostic), as svelte-check reports it2— invocation error (bad flag, missing tsconfig, TypeScript not found)
Roadmap
- [ ] CSS lint diagnostics
Troubleshooting
Stale errors with --incremental — wipe the cache:
rm -rf node_modules/.cache/svelte-check-native and re-run. tsgo's
tsbuildinfo can hold onto stale results; runs without
--incremental (the default, as upstream) never read it.
TS2321 "Excessive stack depth" on your own types — usually a
UnionToRecord<T> that round-trips through UnionToTuple<T>[number].
Iterate T directly in the mapped-type key instead.
Prior art
svelte2tsx/svelte-check— transpiler + CLI whose output shape and flags we match. The.v5fixture corpus fromsvelte2tsxis our parity gate.- TypeScript 7 — the native compiler that does the actual type-checking.
License
MIT
