From 8cdcec4454d0afe90cf67a6ecf2410d11c2f486c Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Sat, 31 Jul 2021 00:43:20 +0800 Subject: [PATCH] Avoid provide hints for binding patterns (#44961) * Avoid provide hints for binding patterns * Rename as 56 --- src/services/inlayHints.ts | 6 ++- .../cases/fourslash/inlayHintsShouldWork56.ts | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/inlayHintsShouldWork56.ts diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 8826639c07646..835dba147c3b3 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -121,8 +121,12 @@ namespace ts.InlayHints { } function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) { + if (!decl.initializer || isBindingPattern(decl.name)) { + return; + } + const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(decl); - if (effectiveTypeAnnotation || !decl.initializer) { + if (effectiveTypeAnnotation) { return; } diff --git a/tests/cases/fourslash/inlayHintsShouldWork56.ts b/tests/cases/fourslash/inlayHintsShouldWork56.ts new file mode 100644 index 0000000000000..98c483625539f --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork56.ts @@ -0,0 +1,40 @@ +/// + +//// const object/*a*/ = { foo: 1, bar: 2 } +//// const array/*b*/ = [1, 2] +//// const a/*c*/ = object; +//// const { foo, bar } = object; +//// const {} = object; +//// const b/*d*/ = array; +//// const [ first, second ] = array; +//// const [] = array; + +const markers = test.markers(); +verify.getInlayHints([ + { + text: ': { foo: number; bar: number; }', + position: markers[0].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, + { + text: ': number[]', + position: markers[1].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, + { + text: ': { foo: number; bar: number; }', + position: markers[2].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, + { + text: ': number[]', + position: markers[3].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + } +], undefined, { + includeInlayVariableTypeHints: true +});