pub struct ObjectLiteralBuilder<'a> { /* private fields */ }Expand description
Builder for constructing object literal types.
This is a solver component that handles the pure type construction aspects of object literals, separate from AST traversal and error reporting.
Implementations§
Source§impl<'a> ObjectLiteralBuilder<'a>
impl<'a> ObjectLiteralBuilder<'a>
Sourcepub fn new(db: &'a dyn TypeDatabase) -> Self
pub fn new(db: &'a dyn TypeDatabase) -> Self
Create a new object literal builder.
Sourcepub fn build_object_type(&self, properties: Vec<PropertyInfo>) -> TypeId
pub fn build_object_type(&self, properties: Vec<PropertyInfo>) -> TypeId
Build object type from properties.
This creates a fresh object type with the given properties. The properties are sorted by name for consistent hashing.
Sourcepub fn build_object_with_index(
&self,
properties: Vec<PropertyInfo>,
string_index: Option<IndexSignature>,
number_index: Option<IndexSignature>,
) -> TypeId
pub fn build_object_with_index( &self, properties: Vec<PropertyInfo>, string_index: Option<IndexSignature>, number_index: Option<IndexSignature>, ) -> TypeId
Build object type with index signature.
Creates an object type with both properties and optional string/number index signatures.
Sourcepub fn merge_spread(
&self,
base_properties: Vec<PropertyInfo>,
spread_type: TypeId,
) -> Vec<PropertyInfo>
pub fn merge_spread( &self, base_properties: Vec<PropertyInfo>, spread_type: TypeId, ) -> Vec<PropertyInfo>
Merge spread properties into base properties.
Given a base set of properties and a spread type, extracts all properties from the spread type and merges them into the base (later properties override).
Example:
const base = { x: 1 };
const spread = { y: 2, x: 3 };
// Result: { x: 3, y: 2 }Sourcepub fn apply_contextual_types(
&self,
properties: Vec<PropertyInfo>,
contextual: TypeId,
) -> Vec<PropertyInfo>
pub fn apply_contextual_types( &self, properties: Vec<PropertyInfo>, contextual: TypeId, ) -> Vec<PropertyInfo>
Apply contextual typing to property types.
When an object literal has a contextual type, each property value should be narrowed by the corresponding property type from the context.
Example:
type Point = { x: number; y: number };
const p: Point = { x: 1, y: '2' }; // Error: '2' is not assignable to numberSourcepub fn collect_spread_properties(
&self,
spread_type: TypeId,
) -> Vec<PropertyInfo>
pub fn collect_spread_properties( &self, spread_type: TypeId, ) -> Vec<PropertyInfo>
Collect all properties for object spread and spread-mutation paths.
This is the solver-side public entrypoint used by query APIs for object
spread property extraction, including CheckerState::get_type_of_object_literal.