Avoid provide hints for binding patterns (#44961)

* Avoid provide hints for binding patterns

* Rename as 56
This commit is contained in:
Wenlu Wang 2021-07-31 00:43:20 +08:00 committed by GitHub
parent 0f6e6efde0
commit 8cdcec4454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -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;
}

View File

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