Skip to content

Commit 8c8f845

Browse files
committed
feat: support spell checking in JSX attribute
1 parent 0975baf commit 8c8f845

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16098,7 +16098,10 @@ namespace ts {
1609816098
const isPerformingExcessPropertyChecks = !(intersectionState & IntersectionState.Target) && (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral);
1609916099
if (isPerformingExcessPropertyChecks) {
1610016100
if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
16101-
if (reportErrors) {
16101+
// Skip report relation error if there is diag with suggestion emitted
16102+
// So the fixSpelling can work with JSX attribute suggestion
16103+
const skipReport = isComparingJsxAttributes && errorInfo?.code === Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code;
16104+
if (reportErrors && !skipReport) {
1610216105
reportRelationError(headMessage, source, target);
1610316106
}
1610416107
return Ternary.False;

src/services/codefixes/fixSpelling.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ namespace ts.codefix {
5252
suggestedSymbol = checker.getSuggestedSymbolForNonexistentModule(node, resolvedSourceFile.symbol);
5353
}
5454
}
55+
else if (isJsxAttribute(parent) && parent.name === node) {
56+
Debug.assertNode(node, isIdentifier, "Expected an identifier for JSX attribute");
57+
const tag = findAncestor(node, isJsxOpeningLikeElement)!;
58+
const props = checker.getContextualTypeForArgumentAtIndex(tag, 0);
59+
suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, props!);
60+
}
5561
else {
5662
const meaning = getMeaningFromLocation(node);
5763
const name = getTextOfNode(node);

0 commit comments

Comments
 (0)