| Crates.io | pctx_type_check_runtime |
| lib.rs | pctx_type_check_runtime |
| version | 0.1.1 |
| created_at | 2026-01-12 20:29:03.327111+00 |
| updated_at | 2026-01-21 01:43:31.897763+00 |
| description | Isolated TypeScript type checking runtime for PCTX |
| homepage | |
| repository | https://github.com/portofcontext/pctx |
| max_upload_size | |
| id | 2038804 |
| size | 9,124,302 |
An isolated TypeScript type checking runtime powered by Deno and the official TypeScript compiler.
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)?;
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) -> boolFilter diagnostics to only include errors that would cause runtime failures.
let errors: Vec<_> = result.diagnostics
.into_iter()
.filter(|d| is_relevant_error(d))
.collect();
CheckResultpub struct CheckResult {
pub success: bool,
pub diagnostics: Vec<Diagnostic>,
}
Diagnosticpub 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
}
TypeCheckErrorpub enum TypeCheckError {
InternalError(String),
ParseError(String),
}
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
build.rsts.createProgram() and getSemanticDiagnostics()The V8 snapshot includes:
lib.d.ts definitions (Promise, Array, console, etc.)See is_relevant_error() for a full list of typescript codes that are ignored