Skip to main content

TypeVisitor

Trait TypeVisitor 

Source
pub trait TypeVisitor: Sized {
    type Output;

Show 34 methods // Required methods fn visit_intrinsic(&mut self, kind: IntrinsicKind) -> Self::Output; fn visit_literal(&mut self, value: &LiteralValue) -> Self::Output; fn default_output() -> Self::Output; // Provided methods fn visit_object(&mut self, _shape_id: u32) -> Self::Output { ... } fn visit_object_with_index(&mut self, _shape_id: u32) -> Self::Output { ... } fn visit_union(&mut self, _list_id: u32) -> Self::Output { ... } fn visit_intersection(&mut self, _list_id: u32) -> Self::Output { ... } fn visit_array(&mut self, _element_type: TypeId) -> Self::Output { ... } fn visit_tuple(&mut self, _list_id: u32) -> Self::Output { ... } fn visit_function(&mut self, _shape_id: u32) -> Self::Output { ... } fn visit_callable(&mut self, _shape_id: u32) -> Self::Output { ... } fn visit_type_parameter( &mut self, _param_info: &TypeParamInfo, ) -> Self::Output { ... } fn visit_bound_parameter(&mut self, _de_bruijn_index: u32) -> Self::Output { ... } fn visit_ref(&mut self, _symbol_ref: u32) -> Self::Output { ... } fn visit_enum(&mut self, _def_id: u32, _member_type: TypeId) -> Self::Output { ... } fn visit_lazy(&mut self, _def_id: u32) -> Self::Output { ... } fn visit_recursive(&mut self, _de_bruijn_index: u32) -> Self::Output { ... } fn visit_application(&mut self, _app_id: u32) -> Self::Output { ... } fn visit_conditional(&mut self, _cond_id: u32) -> Self::Output { ... } fn visit_mapped(&mut self, _mapped_id: u32) -> Self::Output { ... } fn visit_index_access( &mut self, _object_type: TypeId, _key_type: TypeId, ) -> Self::Output { ... } fn visit_template_literal(&mut self, _template_id: u32) -> Self::Output { ... } fn visit_type_query(&mut self, _symbol_ref: u32) -> Self::Output { ... } fn visit_keyof(&mut self, _type_id: TypeId) -> Self::Output { ... } fn visit_readonly_type(&mut self, _inner_type: TypeId) -> Self::Output { ... } fn visit_unique_symbol(&mut self, _symbol_ref: u32) -> Self::Output { ... } fn visit_infer(&mut self, _param_info: &TypeParamInfo) -> Self::Output { ... } fn visit_this_type(&mut self) -> Self::Output { ... } fn visit_string_intrinsic( &mut self, _kind: StringIntrinsicKind, _type_arg: TypeId, ) -> Self::Output { ... } fn visit_error(&mut self) -> Self::Output { ... } fn visit_no_infer(&mut self, _inner: TypeId) -> Self::Output { ... } fn visit_module_namespace(&mut self, _symbol_ref: u32) -> Self::Output { ... } fn visit_type( &mut self, types: &dyn TypeDatabase, type_id: TypeId, ) -> Self::Output { ... } fn visit_type_key( &mut self, _types: &dyn TypeDatabase, type_key: &TypeData, ) -> Self::Output { ... }
}
Expand description

Visitor pattern for TypeData traversal and transformation.

Implement this trait to perform custom operations on types without writing repetitive match statements. Each method corresponds to a TypeData variant and receives the relevant data for that type.

Required Associated Types§

Source

type Output

The output type produced by visiting.

Required Methods§

Source

fn visit_intrinsic(&mut self, kind: IntrinsicKind) -> Self::Output

Visit an intrinsic type (any, unknown, never, void, etc.).

Source

fn visit_literal(&mut self, value: &LiteralValue) -> Self::Output

Visit a literal type (string, number, boolean, bigint literals).

Source

fn default_output() -> Self::Output

Default output for unimplemented variants.

Provided Methods§

Source

fn visit_object(&mut self, _shape_id: u32) -> Self::Output

Visit an object type with properties.

Source

fn visit_object_with_index(&mut self, _shape_id: u32) -> Self::Output

Visit an object type with index signatures.

Source

fn visit_union(&mut self, _list_id: u32) -> Self::Output

Visit a union type (A | B | C).

Source

fn visit_intersection(&mut self, _list_id: u32) -> Self::Output

Visit an intersection type (A & B & C).

Source

fn visit_array(&mut self, _element_type: TypeId) -> Self::Output

Visit an array type T[].

Source

fn visit_tuple(&mut self, _list_id: u32) -> Self::Output

Visit a tuple type [T, U, V].

Source

fn visit_function(&mut self, _shape_id: u32) -> Self::Output

Visit a function type.

Source

fn visit_callable(&mut self, _shape_id: u32) -> Self::Output

Visit a callable type with call/construct signatures.

Source

fn visit_type_parameter(&mut self, _param_info: &TypeParamInfo) -> Self::Output

Visit a type parameter (generic type variable).

Source

fn visit_bound_parameter(&mut self, _de_bruijn_index: u32) -> Self::Output

Visit a bound type parameter using De Bruijn index for alpha-equivalence.

This is used for canonicalizing generic types to achieve structural identity, where type F<T> = T and type G<U> = U are considered identical. The index represents which parameter in the binding scope (0 = innermost).

Source

fn visit_ref(&mut self, _symbol_ref: u32) -> Self::Output

Visit a named type reference (interface, class, type alias).

Source

fn visit_enum(&mut self, _def_id: u32, _member_type: TypeId) -> Self::Output

Visit an enum type with nominal identity and structural member types.

Source

fn visit_lazy(&mut self, _def_id: u32) -> Self::Output

Visit a lazy type reference using DefId.

Source

fn visit_recursive(&mut self, _de_bruijn_index: u32) -> Self::Output

Visit a recursive type reference using De Bruijn index.

This is used for canonicalizing recursive types to achieve O(1) equality. The index represents how many levels up the nesting chain to refer to.

Source

fn visit_application(&mut self, _app_id: u32) -> Self::Output

Visit a generic type application Base.

Source

fn visit_conditional(&mut self, _cond_id: u32) -> Self::Output

Visit a conditional type T extends U ? X : Y.

Source

fn visit_mapped(&mut self, _mapped_id: u32) -> Self::Output

Visit a mapped type { [K in Keys]: V }.

Source

fn visit_index_access( &mut self, _object_type: TypeId, _key_type: TypeId, ) -> Self::Output

Visit an indexed access type T[K].

Source

fn visit_template_literal(&mut self, _template_id: u32) -> Self::Output

Visit a template literal type hello${x}world.

Source

fn visit_type_query(&mut self, _symbol_ref: u32) -> Self::Output

Visit a type query (typeof expr).

Source

fn visit_keyof(&mut self, _type_id: TypeId) -> Self::Output

Visit a keyof type.

Source

fn visit_readonly_type(&mut self, _inner_type: TypeId) -> Self::Output

Visit a readonly type modifier.

Source

fn visit_unique_symbol(&mut self, _symbol_ref: u32) -> Self::Output

Visit a unique symbol type.

Source

fn visit_infer(&mut self, _param_info: &TypeParamInfo) -> Self::Output

Visit an infer type (for type inference in conditional types).

Source

fn visit_this_type(&mut self) -> Self::Output

Visit a this type (polymorphic this parameter).

Source

fn visit_string_intrinsic( &mut self, _kind: StringIntrinsicKind, _type_arg: TypeId, ) -> Self::Output

Visit a string manipulation intrinsic type.

Source

fn visit_error(&mut self) -> Self::Output

Visit an error type.

Source

fn visit_no_infer(&mut self, _inner: TypeId) -> Self::Output

Visit a NoInfer type (TypeScript 5.4+). Traverses the inner type (NoInfer is transparent for traversal).

Source

fn visit_module_namespace(&mut self, _symbol_ref: u32) -> Self::Output

Visit a module namespace type (import * as ns).

Source

fn visit_type( &mut self, types: &dyn TypeDatabase, type_id: TypeId, ) -> Self::Output

Visit a type by dispatching to the appropriate method.

This is the main entry point for using the visitor.

Source

fn visit_type_key( &mut self, _types: &dyn TypeDatabase, type_key: &TypeData, ) -> Self::Output

Visit a TypeData by dispatching to the appropriate method.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§