pub enum SubtypeFailureReason {
Show 25 variants
MissingProperty {
property_name: Atom,
source_type: TypeId,
target_type: TypeId,
},
MissingProperties {
property_names: Vec<Atom>,
source_type: TypeId,
target_type: TypeId,
},
PropertyTypeMismatch {
property_name: Atom,
source_property_type: TypeId,
target_property_type: TypeId,
nested_reason: Option<Box<Self>>,
},
OptionalPropertyRequired {
property_name: Atom,
},
ReadonlyPropertyMismatch {
property_name: Atom,
},
PropertyVisibilityMismatch {
property_name: Atom,
source_visibility: Visibility,
target_visibility: Visibility,
},
PropertyNominalMismatch {
property_name: Atom,
},
ReturnTypeMismatch {
source_return: TypeId,
target_return: TypeId,
nested_reason: Option<Box<Self>>,
},
ParameterTypeMismatch {
param_index: usize,
source_param: TypeId,
target_param: TypeId,
},
TooManyParameters {
source_count: usize,
target_count: usize,
},
TupleElementMismatch {
source_count: usize,
target_count: usize,
},
TupleElementTypeMismatch {
index: usize,
source_element: TypeId,
target_element: TypeId,
},
ArrayElementMismatch {
source_element: TypeId,
target_element: TypeId,
},
IndexSignatureMismatch {
index_kind: &'static str,
source_value_type: TypeId,
target_value_type: TypeId,
},
MissingIndexSignature {
index_kind: &'static str,
},
NoUnionMemberMatches {
source_type: TypeId,
target_union_members: Vec<TypeId>,
},
NoIntersectionMemberMatches {
source_type: TypeId,
target_type: TypeId,
},
NoCommonProperties {
source_type: TypeId,
target_type: TypeId,
},
TypeMismatch {
source_type: TypeId,
target_type: TypeId,
},
IntrinsicTypeMismatch {
source_type: TypeId,
target_type: TypeId,
},
LiteralTypeMismatch {
source_type: TypeId,
target_type: TypeId,
},
ErrorType {
source_type: TypeId,
target_type: TypeId,
},
RecursionLimitExceeded,
ParameterCountMismatch {
source_count: usize,
target_count: usize,
},
ExcessProperty {
property_name: Atom,
target_type: TypeId,
},
}Expand description
Detailed reason for a subtype check failure.
This enum captures all the different ways a subtype check can fail, with enough detail to generate helpful error messages.
§Nesting
Some variants include nested_reason to capture failures in nested types.
For example, a property type mismatch might include why the property types
themselves don’t match.
Variants§
MissingProperty
A required property is missing in the source type.
MissingProperties
Multiple required properties are missing in the source type (TS2739).
PropertyTypeMismatch
Property types are incompatible.
Fields
OptionalPropertyRequired
Optional property cannot satisfy required property.
ReadonlyPropertyMismatch
Readonly property cannot satisfy mutable property.
PropertyVisibilityMismatch
Property visibility mismatch (private/protected vs public).
PropertyNominalMismatch
Property nominal mismatch (separate declarations of private/protected property).
ReturnTypeMismatch
Return types are incompatible.
ParameterTypeMismatch
Parameter types are incompatible.
TooManyParameters
Too many parameters in source.
TupleElementMismatch
Tuple element count mismatch.
TupleElementTypeMismatch
Tuple element type mismatch.
ArrayElementMismatch
Array element type mismatch.
IndexSignatureMismatch
Index signature value type mismatch.
MissingIndexSignature
Missing index signature.
NoUnionMemberMatches
No union member matches.
NoIntersectionMemberMatches
No intersection member matches target (intersection requires at least one member).
NoCommonProperties
No overlapping properties for weak type target.
TypeMismatch
Generic type mismatch (no more specific reason).
IntrinsicTypeMismatch
Intrinsic type mismatch (e.g., string vs number).
LiteralTypeMismatch
Literal type mismatch (e.g., “hello” vs “world” or “hello” vs 42).
ErrorType
Error type encountered - indicates unresolved type that should not be silently compatible.
RecursionLimitExceeded
Recursion limit exceeded during type checking.
ParameterCountMismatch
Parameter count mismatch.
ExcessProperty
Excess property in object literal assignment (TS2353).
Implementations§
Source§impl SubtypeFailureReason
impl SubtypeFailureReason
Sourcepub const fn diagnostic_code(&self) -> u32
pub const fn diagnostic_code(&self) -> u32
Return the primary diagnostic code for this failure reason.
This is the single source of truth for mapping SubtypeFailureReason variants
to diagnostic codes. Both the solver’s to_diagnostic and the checker’s
render_failure_reason should use this to stay in sync.
Sourcepub fn to_diagnostic(&self, source: TypeId, target: TypeId) -> PendingDiagnostic
pub fn to_diagnostic(&self, source: TypeId, target: TypeId) -> PendingDiagnostic
Convert this failure reason to a PendingDiagnostic.
This is the “explain slow” path - called only when we need to report an error and want a detailed message about why the type check failed.
Trait Implementations§
Source§impl Clone for SubtypeFailureReason
impl Clone for SubtypeFailureReason
Source§fn clone(&self) -> SubtypeFailureReason
fn clone(&self) -> SubtypeFailureReason
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more