Skip to content

Commit 8cdcec4

Browse files
authored
Avoid provide hints for binding patterns (#44961)
* Avoid provide hints for binding patterns * Rename as 56
1 parent 0f6e6ef commit 8cdcec4

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/services/inlayHints.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ namespace ts.InlayHints {
121121
}
122122

123123
function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) {
124+
if (!decl.initializer || isBindingPattern(decl.name)) {
125+
return;
126+
}
127+
124128
const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(decl);
125-
if (effectiveTypeAnnotation || !decl.initializer) {
129+
if (effectiveTypeAnnotation) {
126130
return;
127131
}
128132

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// const object/*a*/ = { foo: 1, bar: 2 }
4+
//// const array/*b*/ = [1, 2]
5+
//// const a/*c*/ = object;
6+
//// const { foo, bar } = object;
7+
//// const {} = object;
8+
//// const b/*d*/ = array;
9+
//// const [ first, second ] = array;
10+
//// const [] = array;
11+
12+
const markers = test.markers();
13+
verify.getInlayHints([
14+
{
15+
text: ': { foo: number; bar: number; }',
16+
position: markers[0].position,
17+
kind: ts.InlayHintKind.Type,
18+
whitespaceBefore: true
19+
},
20+
{
21+
text: ': number[]',
22+
position: markers[1].position,
23+
kind: ts.InlayHintKind.Type,
24+
whitespaceBefore: true
25+
},
26+
{
27+
text: ': { foo: number; bar: number; }',
28+
position: markers[2].position,
29+
kind: ts.InlayHintKind.Type,
30+
whitespaceBefore: true
31+
},
32+
{
33+
text: ': number[]',
34+
position: markers[3].position,
35+
kind: ts.InlayHintKind.Type,
36+
whitespaceBefore: true
37+
}
38+
], undefined, {
39+
includeInlayVariableTypeHints: true
40+
});

0 commit comments

Comments
 (0)