Expand description
Query-Based Structural Solver
This module implements a declarative, query-based type solver architecture. It uses:
- Ena: For unification (Union-Find) in generic type inference
- Custom
TypeData: Structural type representation with interning - Cycle Detection: Coinductive semantics for recursive types
Key benefits:
- O(1) type equality via interning (
TypeIdcomparison) - Automatic cycle handling via coinductive semantics
- Lazy evaluation - only compute types that are queried
Re-exports§
pub use operations::infer_generic_function;pub use visitor::ConstAssertionVisitor;pub use visitor::ObjectTypeKind;pub use visitor::RecursiveTypeCollector;pub use visitor::TypeCollectorVisitor;pub use visitor::TypeKind;pub use visitor::TypeKindVisitor;pub use visitor::TypePredicateVisitor;pub use visitor::TypeVisitor;pub use visitor::application_id;pub use visitor::array_element_type;pub use visitor::bound_parameter_index;pub use visitor::callable_shape_id;pub use visitor::classify_object_type;pub use visitor::collect_all_types;pub use visitor::collect_enum_def_ids;pub use visitor::collect_lazy_def_ids;pub use visitor::collect_referenced_types;pub use visitor::collect_type_queries;pub use visitor::conditional_type_id;pub use visitor::contains_error_type;pub use visitor::contains_infer_types;pub use visitor::contains_this_type;pub use visitor::contains_type_matching;pub use visitor::contains_type_parameters;pub use visitor::enum_components;pub use visitor::for_each_child;pub use visitor::function_shape_id;pub use visitor::index_access_parts;pub use visitor::intersection_list_id;pub use visitor::intrinsic_kind;pub use visitor::is_array_type;pub use visitor::is_conditional_type;pub use visitor::is_empty_object_type;pub use visitor::is_empty_object_type_db;pub use visitor::is_enum_type;pub use visitor::is_error_type;pub use visitor::is_function_type;pub use visitor::is_function_type_db;pub use visitor::is_generic_application;pub use visitor::is_index_access_type;pub use visitor::is_intersection_type;pub use visitor::is_literal_type;pub use visitor::is_literal_type_db;pub use visitor::is_mapped_type;pub use visitor::is_module_namespace_type;pub use visitor::is_module_namespace_type_db;pub use visitor::is_object_like_type;pub use visitor::is_object_like_type_db;pub use visitor::is_primitive_type;pub use visitor::is_template_literal_type;pub use visitor::is_this_type;pub use visitor::is_tuple_type;pub use visitor::is_type_kind;pub use visitor::is_type_parameter;pub use visitor::is_type_reference;pub use visitor::is_union_type;pub use visitor::is_unit_type;pub use visitor::keyof_inner_type;pub use visitor::lazy_def_id;pub use visitor::literal_number;pub use visitor::literal_string;pub use visitor::literal_value;pub use visitor::mapped_type_id;pub use visitor::module_namespace_symbol_ref;pub use visitor::no_infer_inner_type;pub use visitor::object_shape_id;pub use visitor::object_with_index_shape_id;pub use visitor::readonly_inner_type;pub use visitor::recursive_index;pub use visitor::ref_symbol;pub use visitor::string_intrinsic_components;pub use visitor::template_literal_id;pub use visitor::test_type;pub use visitor::tuple_list_id;pub use visitor::type_param_info;pub use visitor::type_query_symbol;pub use visitor::union_list_id;pub use visitor::unique_symbol_ref;pub use visitor::walk_referenced_types;pub use operations::AssignabilityChecker;pub use operations::CallEvaluator;pub use operations::CallResult;pub use operations::MAX_CONSTRAINT_RECURSION_DEPTH;pub use operations::get_contextual_signature_with_compat_checker;pub use subtype::TypeEnvironment;pub use subtype::TypeResolver;pub use types::CallSignature;pub use types::CallableShapeId;pub use types::IntrinsicKind;pub use types::LiteralValue;pub use types::MappedModifier;pub use types::ObjectShapeId;pub use types::PropertyInfo;pub use types::PropertyLookup;pub use types::SymbolRef;pub use types::TypeApplication;pub use types::TypeApplicationId;pub use types::TypeData;pub use types::TypeId;pub use types::TypeListId;pub use types::Visibility;pub use types::is_compiler_managed_type;pub use types::CallableShape;pub use types::ConditionalType;pub use types::FunctionShape;pub use types::FunctionShapeId;pub use types::IndexSignature;pub use types::MappedType;pub use types::MappedTypeId;pub use types::ObjectFlags;pub use types::ObjectShape;pub use types::OrderedFloat;pub use types::ParamInfo;pub use types::RelationCacheKey;pub use types::TemplateSpan;pub use types::TupleElement;pub use types::TupleListId;pub use types::TypeParamInfo;pub use types::TypePredicate;pub use types::TypePredicateTarget;pub use binary_ops::*;pub use canonicalize::*;pub use compat::*;pub use compound_assignment::*;pub use def::*;pub use element_access::*;pub use freshness::*;pub use inheritance::*;pub use judge::*;pub use objects::*;pub use relation_queries::*;pub use sound::*;pub use unsoundness_audit::*;pub use variance::*;pub use widening::*;
Modules§
- binary_
ops - Binary operation type evaluation.
- canonicalize
- Canonicalization for structural type identity (Task #32: Graph Isomorphism)
- compat
- TypeScript compatibility layer for assignability rules.
- compound_
assignment - def
- Definition identifiers and storage for the solver.
- element_
access - evaluate_
rules - Type evaluation rules organized by type category.
- expression_
ops - Expression type computation operations.
- freshness
- Freshness helpers for object literal excess property checking.
- inheritance
- Inheritance Graph Solver
- judge
- The Judge: Query-based type algebra engine.
- objects
- Property collection and merging for intersection types.
- operations
- Type operations and expression evaluation.
- operations_
generics - Generic type instantiation validation.
- operations_
iterators - Iterator and async iterator type extraction.
- operations_
property - Property access resolution (
PropertyAccessEvaluator) for resolving property access on types (obj.prop, obj[“key”], etc.). - recursion
- Unified recursion guard for cycle detection, depth limiting, and iteration bounding in recursive type computations.
- relation_
queries - Unified relation query entrypoints.
- sound
- Sound Mode: Strict type checking beyond TypeScript’s defaults.
- tracer
- Tracer-based subtype checking.
- type_
queries - Type Query Functions
- type_
queries_ classifiers - Additional type query classifiers.
- type_
queries_ data - Type Content Queries and Data Extraction Helpers
- type_
queries_ extended - Extended Type Query Functions
- type_
queries_ flow - Control Flow and Advanced Type Classification Queries
- type_
resolver - Type resolution trait and environment.
- types
- Type representation for the structural solver.
- unsoundness_
audit - TypeScript Unsoundness Catalog Implementation Audit
- utils
- Shared utility functions for the solver module.
- variance
- Variance calculation for type parameters.
- visitor
- Type Visitor Pattern
- widening
- Type widening operations for literal types.
Structs§
- AnyPropagation
Rules - Rules for
anypropagation in type checking. - Application
Evaluator - Evaluator for generic type applications.
- Class
Type Builder - Builder for constructing class instance types.
- Constraint
Set - Constraint set for an inference variable. Tracks both lower bounds (L <: α) and upper bounds (α <: U).
- Contextual
Type Context - Context for contextual typing. Holds the expected type and provides methods to extract type information.
- Diagnostic
Builder - Builder for creating type error diagnostics.
- Diagnostic
Collector - A diagnostic collector that accumulates diagnostics with source tracking.
- Discriminant
Info - Result of finding discriminant properties in a union.
- Flow
Facts - Flow facts that represent the state of variables at a specific program point.
- Flow
Type Evaluator - Flow type evaluator that integrates flow analysis with the solver.
- Index
Signature Resolver - Resolver for index signature queries on types.
- Inference
Candidate - A candidate type for an inference variable.
- Inference
Context - Type inference context for a single function call or expression.
- Inference
Info - Value stored for each inference variable root.
- Inference
Var - An inference variable representing an unknown type. These are created when instantiating generic functions.
- Narrowing
Cache - Narrowing context for type guards and control flow analysis. Shared across multiple narrowing contexts to persist resolution results.
- Narrowing
Context - Narrowing context for type guards and control flow analysis.
- Narrowing
Result - Result of a narrowing operation.
- Object
Literal Builder - Builder for constructing object literal types.
- Pending
Diagnostic - A pending diagnostic that hasn’t been rendered yet.
- Pending
Diagnostic Builder - Builder for creating lazy pending diagnostics.
- Query
Cache - Query database wrapper with basic caching.
- Relation
Cache Stats - Source
Location - Tracks source locations for AST nodes during type checking.
- Source
Span - A source location span.
- Spanned
Diagnostic Builder - A diagnostic builder that automatically attaches source spans.
- Subtype
Checker - Subtype checking context. Maintains the “seen” set for cycle detection.
- Type
Evaluator - Type evaluator for meta-types.
- Type
Factory - Type
Formatter - Context for generating type strings.
- Type
Instantiator - Instantiator for applying type substitutions.
- Type
Interner - Type interning table with lock-free concurrent access.
- Type
Substitution - A substitution map from type parameter names to concrete types.
Enums§
- AnyPropagation
Mode - Controls how
anyis treated during subtype checks. - Apparent
Member Kind - Application
Result - Result of application type evaluation.
- Conditional
Result - Result of conditional type evaluation
- Constraint
Conflict - Conflict detected between constraints on an inference variable.
- Diagnostic
Arg - Argument for a diagnostic message template.
- Diagnostic
Severity - Diagnostic severity level.
- Index
Kind - Distinguishes between string and numeric index signatures.
- Inference
Error - Inference error
- Relation
Cache Probe - Subtype
Failure Reason - Detailed reason for a subtype check failure.
- Subtype
Result - Result of a subtype check
- Type
Guard - AST-agnostic representation of a type narrowing condition.
- Typeof
Kind - The result of a
typeofexpression, restricted to the 8 standard JavaScript types.
Constants§
- ARRAY_
METHODS_ RETURN_ ANY - Array methods that return any (used for apparent type computation).
- ARRAY_
METHODS_ RETURN_ BOOLEAN - Array methods that return boolean.
- ARRAY_
METHODS_ RETURN_ NUMBER - Array methods that return number.
- ARRAY_
METHODS_ RETURN_ STRING - Array methods that return string.
- ARRAY_
METHODS_ RETURN_ VOID - Array methods that return void.
- MAX_
CONSTRAINT_ ITERATIONS - Maximum iterations for constraint strengthening loops to prevent infinite loops.
- MAX_
INSTANTIATION_ DEPTH - Maximum depth for recursive type instantiation.
- MAX_
TYPE_ RECURSION_ DEPTH - Maximum recursion depth for type containment checks.
- MAX_
VISITING_ SET_ SIZE - Maximum number of unique types to track in the visiting set. Prevents unbounded memory growth in pathological cases.
Traits§
- Query
Database - Query layer for higher-level solver operations.
- Type
Database - Query interface for the solver.
Functions§
- apparent_
object_ member_ kind - apparent_
primitive_ member_ kind - apparent_
primitive_ members - apply_
contextual_ type - Apply contextual type to infer a more specific type.
- are_
types_ structurally_ identical - Check if two types are structurally identical using De Bruijn indices for cycles.
- can_
be_ nullish - Check if a type can be nullish (contains null/undefined/void).
- evaluate_
conditional - Convenience function for evaluating conditional types
- evaluate_
index_ access - Convenience function for evaluating index access types
- evaluate_
index_ access_ with_ options - Convenience function for evaluating index access types with options.
- evaluate_
keyof - Convenience function for evaluating keyof types
- evaluate_
mapped - Convenience function for evaluating mapped types
- evaluate_
type - Convenience function for full type evaluation
- find_
discriminants - Convenience function for finding discriminants.
- instantiate_
type - Convenience function for instantiating a type with a substitution.
- is_
definitely_ nullish - Check if a type is definitely nullish (only null/undefined/void).
- is_
nullish_ type - Check if a type is nullish (null/undefined/void or union containing them).
- is_
subtype_ of - Convenience function for one-off subtype checks (without resolver)
- narrow_
by_ discriminant - Convenience function for narrowing by discriminant.
- narrow_
by_ typeof - Convenience function for typeof narrowing.
- remove_
definitely_ falsy_ types - Remove types that are definitely falsy from a union, without narrowing
non-falsy types. This matches TypeScript’s
removeDefinitelyFalsyTypes: removesnull,undefined,void,false,0,"",0nbut keepsboolean,string,number,bigint, and object types unchanged. - remove_
nullish - Remove nullish parts of a type (non-null assertion).
- split_
nullish_ type - Split a type into its non-nullish part and its nullish cause.
- substitute_
this_ type - Substitute
ThisTypewith a concrete type throughout a type. - type_
contains_ nullish - Check if a type (possibly a union) contains null or undefined.
- type_
contains_ undefined - Check if a type contains undefined (or void).
- would_
create_ inheritance_ cycle - Detects if adding a parent to a child would create a cycle in the inheritance graph.