Skip to content

Commit

Permalink
Avoid provide hints for binding patterns (#44961)
Browse files Browse the repository at this point in the history
* Avoid provide hints for binding patterns

* Rename as 56
  • Loading branch information
Kingwl committed Jul 30, 2021
1 parent 0f6e6ef commit 8cdcec4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/services/inlayHints.ts
Expand Up @@ -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;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/cases/fourslash/inlayHintsShouldWork56.ts
@@ -0,0 +1,40 @@
/// <reference path="fourslash.ts" />

//// 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
});

0 comments on commit 8cdcec4

Please sign in to comment.