4 releases
Uses new Rust 2024
| 0.1.3 | Mar 13, 2026 |
|---|---|
| 0.1.2 | Feb 4, 2026 |
| 0.1.1 | Jan 21, 2026 |
| 0.1.0 | Jan 12, 2026 |
#765 in Asynchronous
33,966 downloads per month
Used in 6 crates
(via pctx_executor)
9MB
183K
SLoC
PCTX Type Check
An isolated TypeScript type checking runtime powered by Deno and the official TypeScript compiler.
Quick Start
use pctx_type_check::{type_check_async, type_check};
// Async API (preferred)
let code = r#"
const x: number = 42;
const y: string = "hello";
export default x + y.length;
"#;
let result = type_check_async(code).await?;
if result.success {
println!("✓ Type check passed!");
} else {
for diagnostic in result.diagnostics {
println!("{}: {}", diagnostic.severity, diagnostic.message);
}
}
// Sync API (creates tokio runtime if needed)
let result = type_check(code)?;
API Reference
Core Functions
type_check_async(code: &str) -> Result<CheckResult>
Asynchronously type check TypeScript code. Preferred API for async contexts.
let result = type_check_async(code).await?;
assert!(result.success);
type_check(code: &str) -> Result<CheckResult>
Synchronously type check TypeScript code. Creates a tokio runtime if needed.
let result = type_check(code)?;
assert!(result.success);
is_relevant_error(diagnostic: &Diagnostic) -> bool
Filter diagnostics to only include errors that would cause runtime failures.
let errors: Vec<_> = result.diagnostics
.into_iter()
.filter(|d| is_relevant_error(d))
.collect();
Types
CheckResult
pub struct CheckResult {
pub success: bool,
pub diagnostics: Vec<Diagnostic>,
}
Diagnostic
pub struct Diagnostic {
pub message: String,
pub line: Option<usize>,
pub column: Option<usize>,
pub severity: String, // "error" or "warning"
pub code: Option<u32>, // TypeScript error code
}
TypeCheckError
pub enum TypeCheckError {
InternalError(String),
ParseError(String),
}
Examples
Catching Type Errors
let code = r#"
const x: number = "string"; // Type error!
export default x;
"#;
let result = type_check_async(code).await?;
assert!(!result.success);
assert_eq!(result.diagnostics[0].code, Some(2322)); // Type mismatch
Architecture
- Build Phase: TypeScript compiler (9MB) is embedded in a V8 snapshot via
build.rs - Runtime Phase: Each type check creates an isolated Deno runtime with the snapshot
- Type Checking: Runtime executes
ts.createProgram()andgetSemanticDiagnostics() - Cleanup: Runtime is dropped after check, freeing all memory
Snapshot Contents
The V8 snapshot includes:
- TypeScript 5.3.3 compiler (full semantic analysis)
- Minimal
lib.d.tsdefinitions (Promise, Array, console, etc.) - MCP SDK type definitions
- Type checking orchestration logic
Filtered Error Codes
See is_relevant_error() for a full list of typescript codes that are ignored
Dependencies
~119MB
~2M SLoC