From bcf994996ea0ddd8ca7daadd6b5fbc712eb5ce6b Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 2 Sep 2022 02:59:29 +0300 Subject: [PATCH] fix(50079): show deprecated on JSX attributes (#50084) --- src/compiler/checker.ts | 7 ++++++ .../fourslash/jsdocDeprecated_suggestion18.ts | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/cases/fourslash/jsdocDeprecated_suggestion18.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 259ffc6312017..85c01429e4ce6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -28375,6 +28375,7 @@ namespace ts { */ function createJsxAttributesTypeFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement, checkMode: CheckMode | undefined) { const attributes = openingLikeElement.attributes; + const attributesType = getContextualType(attributes, ContextFlags.None); const allAttributesTable = strictNullChecks ? createSymbolTable() : undefined; let attributesTable = createSymbolTable(); let spread: Type = emptyJsxObjectType; @@ -28403,6 +28404,12 @@ namespace ts { if (attributeDecl.name.escapedText === jsxChildrenPropertyName) { explicitlySpecifyChildrenAttribute = true; } + if (attributesType) { + const prop = getPropertyOfType(attributesType, member.escapedName); + if (prop && prop.declarations && isDeprecatedSymbol(prop)) { + addDeprecatedSuggestion(attributeDecl.name, prop.declarations, attributeDecl.name.escapedText as string); + } + } } else { Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute); diff --git a/tests/cases/fourslash/jsdocDeprecated_suggestion18.ts b/tests/cases/fourslash/jsdocDeprecated_suggestion18.ts new file mode 100644 index 0000000000000..abab252a190c0 --- /dev/null +++ b/tests/cases/fourslash/jsdocDeprecated_suggestion18.ts @@ -0,0 +1,25 @@ +/// + +// @jsx: preserve +// @filename: foo.tsx +////interface Props { +//// /** @deprecated */ +//// x: number; +//// y: number; +////} +////function A(props: Props) { +//// return
{props.y}
+////} +////function B() { +//// return +////} + +const [range] = test.ranges(); +verify.getSuggestionDiagnostics([ + { + "code": 6385, + "message": "'x' is deprecated.", + "reportsDeprecated": true, + "range": range + }, +]);