mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-16 06:28:12 -05:00
feat(49385): forbid inlay hints for some kind of initialized declarations (#49412)
.
This commit is contained in:
@@ -121,7 +121,7 @@ namespace ts.InlayHints {
|
||||
}
|
||||
|
||||
function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) {
|
||||
if (!decl.initializer || isBindingPattern(decl.name)) {
|
||||
if (!decl.initializer || isBindingPattern(decl.name) || isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -272,8 +272,11 @@ namespace ts.InlayHints {
|
||||
|
||||
for (let i = 0; i < node.parameters.length && i < signature.parameters.length; ++i) {
|
||||
const param = node.parameters[i];
|
||||
const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(param);
|
||||
if (!isHintableDeclaration(param)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const effectiveTypeAnnotation = getEffectiveTypeAnnotationNode(param);
|
||||
if (effectiveTypeAnnotation) {
|
||||
continue;
|
||||
}
|
||||
@@ -323,5 +326,13 @@ namespace ts.InlayHints {
|
||||
function isUndefined(name: __String) {
|
||||
return name === "undefined";
|
||||
}
|
||||
|
||||
function isHintableDeclaration(node: VariableDeclaration | ParameterDeclaration) {
|
||||
if ((isParameterDeclaration(node) || isVariableDeclaration(node) && isVarConst(node)) && node.initializer) {
|
||||
const initializer = skipParentheses(node.initializer);
|
||||
return !(isHintableLiteral(initializer) || isNewExpression(initializer) || isObjectLiteralExpression(initializer) || isAssertionExpression(initializer));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user