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

Download history 375/week @ 2026-01-28 8194/week @ 2026-02-04 7881/week @ 2026-02-11 5253/week @ 2026-02-18 6707/week @ 2026-02-25 7155/week @ 2026-03-04 8208/week @ 2026-03-11 8131/week @ 2026-03-18 8622/week @ 2026-03-25 8524/week @ 2026-04-01 7438/week @ 2026-04-08

33,966 downloads per month
Used in 6 crates (via pctx_executor)

MIT license

9MB
183K SLoC

JavaScript 183K SLoC // 0.0% comments Rust 195 SLoC // 0.1% comments

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

  1. Build Phase: TypeScript compiler (9MB) is embedded in a V8 snapshot via build.rs
  2. Runtime Phase: Each type check creates an isolated Deno runtime with the snapshot
  3. Type Checking: Runtime executes ts.createProgram() and getSemanticDiagnostics()
  4. 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.ts definitions (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