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§
Required Methods§
Sourcefn visit_intrinsic(&mut self, kind: IntrinsicKind) -> Self::Output
fn visit_intrinsic(&mut self, kind: IntrinsicKind) -> Self::Output
Visit an intrinsic type (any, unknown, never, void, etc.).
Sourcefn visit_literal(&mut self, value: &LiteralValue) -> Self::Output
fn visit_literal(&mut self, value: &LiteralValue) -> Self::Output
Visit a literal type (string, number, boolean, bigint literals).
Sourcefn default_output() -> Self::Output
fn default_output() -> Self::Output
Default output for unimplemented variants.
Provided Methods§
Sourcefn visit_object(&mut self, _shape_id: u32) -> Self::Output
fn visit_object(&mut self, _shape_id: u32) -> Self::Output
Visit an object type with properties.
Sourcefn visit_object_with_index(&mut self, _shape_id: u32) -> Self::Output
fn visit_object_with_index(&mut self, _shape_id: u32) -> Self::Output
Visit an object type with index signatures.
Sourcefn visit_union(&mut self, _list_id: u32) -> Self::Output
fn visit_union(&mut self, _list_id: u32) -> Self::Output
Visit a union type (A | B | C).
Sourcefn visit_intersection(&mut self, _list_id: u32) -> Self::Output
fn visit_intersection(&mut self, _list_id: u32) -> Self::Output
Visit an intersection type (A & B & C).
Sourcefn visit_array(&mut self, _element_type: TypeId) -> Self::Output
fn visit_array(&mut self, _element_type: TypeId) -> Self::Output
Visit an array type T[].
Sourcefn visit_tuple(&mut self, _list_id: u32) -> Self::Output
fn visit_tuple(&mut self, _list_id: u32) -> Self::Output
Visit a tuple type [T, U, V].
Sourcefn visit_function(&mut self, _shape_id: u32) -> Self::Output
fn visit_function(&mut self, _shape_id: u32) -> Self::Output
Visit a function type.
Sourcefn visit_callable(&mut self, _shape_id: u32) -> Self::Output
fn visit_callable(&mut self, _shape_id: u32) -> Self::Output
Visit a callable type with call/construct signatures.
Sourcefn visit_type_parameter(&mut self, _param_info: &TypeParamInfo) -> Self::Output
fn visit_type_parameter(&mut self, _param_info: &TypeParamInfo) -> Self::Output
Visit a type parameter (generic type variable).
Sourcefn visit_bound_parameter(&mut self, _de_bruijn_index: u32) -> Self::Output
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).
Sourcefn visit_ref(&mut self, _symbol_ref: u32) -> Self::Output
fn visit_ref(&mut self, _symbol_ref: u32) -> Self::Output
Visit a named type reference (interface, class, type alias).
Sourcefn visit_enum(&mut self, _def_id: u32, _member_type: TypeId) -> Self::Output
fn visit_enum(&mut self, _def_id: u32, _member_type: TypeId) -> Self::Output
Visit an enum type with nominal identity and structural member types.
Sourcefn visit_lazy(&mut self, _def_id: u32) -> Self::Output
fn visit_lazy(&mut self, _def_id: u32) -> Self::Output
Visit a lazy type reference using DefId.
Sourcefn visit_recursive(&mut self, _de_bruijn_index: u32) -> Self::Output
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.
Sourcefn visit_application(&mut self, _app_id: u32) -> Self::Output
fn visit_application(&mut self, _app_id: u32) -> Self::Output
Visit a generic type application Base
Sourcefn visit_conditional(&mut self, _cond_id: u32) -> Self::Output
fn visit_conditional(&mut self, _cond_id: u32) -> Self::Output
Visit a conditional type T extends U ? X : Y.
Sourcefn visit_mapped(&mut self, _mapped_id: u32) -> Self::Output
fn visit_mapped(&mut self, _mapped_id: u32) -> Self::Output
Visit a mapped type { [K in Keys]: V }.
Sourcefn visit_index_access(
&mut self,
_object_type: TypeId,
_key_type: TypeId,
) -> Self::Output
fn visit_index_access( &mut self, _object_type: TypeId, _key_type: TypeId, ) -> Self::Output
Visit an indexed access type T[K].
Sourcefn visit_template_literal(&mut self, _template_id: u32) -> Self::Output
fn visit_template_literal(&mut self, _template_id: u32) -> Self::Output
Visit a template literal type hello${x}world.
Sourcefn visit_type_query(&mut self, _symbol_ref: u32) -> Self::Output
fn visit_type_query(&mut self, _symbol_ref: u32) -> Self::Output
Visit a type query (typeof expr).
Sourcefn visit_keyof(&mut self, _type_id: TypeId) -> Self::Output
fn visit_keyof(&mut self, _type_id: TypeId) -> Self::Output
Visit a keyof type.
Sourcefn visit_readonly_type(&mut self, _inner_type: TypeId) -> Self::Output
fn visit_readonly_type(&mut self, _inner_type: TypeId) -> Self::Output
Visit a readonly type modifier.
Sourcefn visit_unique_symbol(&mut self, _symbol_ref: u32) -> Self::Output
fn visit_unique_symbol(&mut self, _symbol_ref: u32) -> Self::Output
Visit a unique symbol type.
Sourcefn visit_infer(&mut self, _param_info: &TypeParamInfo) -> Self::Output
fn visit_infer(&mut self, _param_info: &TypeParamInfo) -> Self::Output
Visit an infer type (for type inference in conditional types).
Sourcefn visit_this_type(&mut self) -> Self::Output
fn visit_this_type(&mut self) -> Self::Output
Visit a this type (polymorphic this parameter).
Sourcefn visit_string_intrinsic(
&mut self,
_kind: StringIntrinsicKind,
_type_arg: TypeId,
) -> Self::Output
fn visit_string_intrinsic( &mut self, _kind: StringIntrinsicKind, _type_arg: TypeId, ) -> Self::Output
Visit a string manipulation intrinsic type.
Sourcefn visit_error(&mut self) -> Self::Output
fn visit_error(&mut self) -> Self::Output
Visit an error type.
Sourcefn visit_no_infer(&mut self, _inner: TypeId) -> Self::Output
fn visit_no_infer(&mut self, _inner: TypeId) -> Self::Output
Visit a NoInferNoInfer is transparent for traversal).
Sourcefn visit_module_namespace(&mut self, _symbol_ref: u32) -> Self::Output
fn visit_module_namespace(&mut self, _symbol_ref: u32) -> Self::Output
Visit a module namespace type (import * as ns).
Sourcefn visit_type(
&mut self,
types: &dyn TypeDatabase,
type_id: TypeId,
) -> Self::Output
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.
Sourcefn visit_type_key(
&mut self,
_types: &dyn TypeDatabase,
type_key: &TypeData,
) -> Self::Output
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.