Skip to content

Commit 420e934

Browse files
committed
add ts2326
1 parent b97d11c commit 420e934

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/diagnostics/suggestions.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,31 @@ impl ErrorDiagnostic for ErrorCode {
8888
ErrorCode::UnionTooComplex => suggest_union_too_complex(),
8989
ErrorCode::JsxElementIsNotCallable => suggest_jsx_element_not_a_fn(err),
9090
ErrorCode::InvalidJsxConfigurationUmd => suggest_jsx_incorrect_configuration_umd(err),
91+
ErrorCode::TypesOfPropertyAreIncompatible => {
92+
suggest_types_of_property_are_incompatible(err)
93+
}
9194
ErrorCode::Unsupported(_) => None,
9295
}
9396
}
9497
}
9598

99+
/// Suggestion for when types of a property are incompatible between source and target
100+
fn suggest_types_of_property_are_incompatible(err: &TsError) -> Option<Suggestion> {
101+
let property = extract_first_quoted(&err.message)?;
102+
103+
Some(Suggestion {
104+
suggestions: vec![format!(
105+
"Types of property `{}` are incompatible between the source and target.",
106+
property.red().bold()
107+
)],
108+
help: Some(
109+
"Ensure that the property types are compatible or perform necessary type conversions."
110+
.to_string(),
111+
),
112+
span: None,
113+
})
114+
}
115+
96116
/// Suggestion for when jsx is configured incorrectly and the requested module is resolved to a UMD
97117
/// global.
98118
fn suggest_jsx_incorrect_configuration_umd(err: &TsError) -> Option<Suggestion> {

src/error/codes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub enum ErrorCode {
77
PropertyDoesNotExist,
88
TypeAssertionInJsNotAllowed,
99
MappedTypeMustBeStatic,
10+
TypesOfPropertyAreIncompatible,
1011

1112
// null safety
1213
ObjectIsPossiblyNull,
@@ -130,6 +131,7 @@ impl ErrorCode {
130131
"TS2590" => ErrorCode::UnionTooComplex,
131132
"TS2604" => ErrorCode::JsxElementIsNotCallable,
132133
"TS2686" => ErrorCode::InvalidJsxConfigurationUmd,
134+
"TS2326" => ErrorCode::TypesOfPropertyAreIncompatible,
133135

134136
other => {
135137
if let Some(num_str) = other.strip_prefix("TS")
@@ -198,6 +200,7 @@ impl ErrorCode {
198200
ErrorCode::UnionTooComplex => "TS2590",
199201
ErrorCode::JsxElementIsNotCallable => "TS2604",
200202
ErrorCode::InvalidJsxConfigurationUmd => "TS2686",
203+
ErrorCode::TypesOfPropertyAreIncompatible => "TS2326",
201204
ErrorCode::Unsupported(_) => {
202205
// This will return a static string for known codes, but for unsupported codes,
203206
// we return a dynamically allocated string. To keep the return type consistent,

0 commit comments

Comments
 (0)