Skip to content

Commit 0975baf

Browse files
committed
feat: add name suggestion for JSX
1 parent 9fe25ca commit 0975baf

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16313,18 +16313,20 @@ namespace ts {
1631316313
if (isJsxAttributes(errorNode) || isJsxOpeningLikeElement(errorNode) || isJsxOpeningLikeElement(errorNode.parent)) {
1631416314
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
1631516315
// However, using an object-literal error message will be very confusing to the users so we give different a message.
16316-
// TODO: Spelling suggestions for excess jsx attributes (needs new diagnostic messages)
1631716316
if (prop.valueDeclaration && isJsxAttribute(prop.valueDeclaration) && getSourceFileOfNode(errorNode) === getSourceFileOfNode(prop.valueDeclaration.name)) {
1631816317
// Note that extraneous children (as in `<NoChild>extra</NoChild>`) don't pass this check,
1631916318
// since `children` is a SyntaxKind.PropertySignature instead of a SyntaxKind.JsxAttribute.
1632016319
errorNode = prop.valueDeclaration.name;
1632116320
}
16322-
reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
16321+
const propName = symbolToString(prop);
16322+
const suggestion = getSuggestionForNonexistentProperty(propName, errorTarget);
16323+
if (suggestion) reportError(Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, propName, typeToString(errorTarget), suggestion);
16324+
else reportError(Diagnostics.Property_0_does_not_exist_on_type_1, propName, typeToString(errorTarget));
1632316325
}
1632416326
else {
1632516327
// use the property's value declaration if the property is assigned inside the literal itself
1632616328
const objectLiteralDeclaration = source.symbol && firstOrUndefined(source.symbol.declarations);
16327-
let suggestion;
16329+
let suggestion: string | undefined;
1632816330
if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration) && getSourceFileOfNode(objectLiteralDeclaration) === getSourceFileOfNode(errorNode)) {
1632916331
const propDeclaration = prop.valueDeclaration as ObjectLiteralElementLike;
1633016332
Debug.assertNode(propDeclaration, isObjectLiteralElementLike);

0 commit comments

Comments
 (0)