Skip to main content

tsz_checker/
judge_integration.rs

1//! Judge Integration for the Checker
2//!
3//! Provides integration between the Checker and the Solver's Judge trait.
4
5use crate::state::CheckerState;
6use tsz_solver::TypeId;
7use tsz_solver::judge::{DefaultJudge, Judge, JudgeConfig};
8
9impl<'a> CheckerState<'a> {
10    /// Execute a closure with a configured Judge instance.
11    ///
12    /// The Judge provides pure type algebra operations (`is_subtype`, evaluate, etc.)
13    /// without TypeScript-specific quirks. For assignability checking with TS rules,
14    /// use `is_assignable_to` which goes through the Lawyer (`CompatChecker`) layer.
15    pub fn with_judge<R, F>(&self, f: F) -> R
16    where
17        F: FnOnce(&DefaultJudge<'_>) -> R,
18    {
19        let env = self.ctx.type_env.borrow();
20        let config = JudgeConfig {
21            strict_null_checks: self.ctx.strict_null_checks(),
22            strict_function_types: self.ctx.strict_function_types(),
23            exact_optional_property_types: self.ctx.exact_optional_property_types(),
24            no_unchecked_indexed_access: self.ctx.no_unchecked_indexed_access(),
25            sound_mode: self.ctx.sound_mode(),
26        };
27        let judge = DefaultJudge::new(self.ctx.types, &env, config);
28        f(&judge)
29    }
30
31    /// Evaluate a type using the Judge.
32    ///
33    /// Expands meta-types (conditionals, mapped types, etc.) to their concrete forms.
34    pub fn judge_evaluate(&self, type_id: TypeId) -> TypeId {
35        self.with_judge(|judge| judge.evaluate(type_id))
36    }
37}