mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
Fixed an out-of-order quick info issue with contextual rest parameter (#57580)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
parent
9bdfa441c6
commit
3e91592b06
@ -15122,11 +15122,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return symbol && withAugmentations ? getMergedSymbol(symbol) : symbol;
|
||||
}
|
||||
|
||||
function hasEffectiveQuestionToken(node: ParameterDeclaration | JSDocParameterTag | JSDocPropertyTag) {
|
||||
return hasQuestionToken(node) || isOptionalJSDocPropertyLikeTag(node) || isParameter(node) && isJSDocOptionalParameter(node);
|
||||
}
|
||||
|
||||
function isOptionalParameter(node: ParameterDeclaration | JSDocParameterTag | JSDocPropertyTag) {
|
||||
if (hasQuestionToken(node) || isOptionalJSDocPropertyLikeTag(node) || isJSDocOptionalParameter(node)) {
|
||||
if (hasEffectiveQuestionToken(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isParameter(node)) {
|
||||
return false;
|
||||
}
|
||||
if (node.initializer) {
|
||||
const signature = getSignatureFromDeclaration(node.parent);
|
||||
const parameterIndex = node.parent.parameters.indexOf(node);
|
||||
@ -15256,10 +15262,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
// Record a new minimum argument count if this is not an optional parameter
|
||||
const isOptionalParameter = isOptionalJSDocPropertyLikeTag(param) ||
|
||||
param.initializer || param.questionToken || isRestParameter(param) ||
|
||||
iife && parameters.length > iife.arguments.length && !type ||
|
||||
isJSDocOptionalParameter(param);
|
||||
const isOptionalParameter = hasEffectiveQuestionToken(param) ||
|
||||
isParameter(param) && param.initializer || isRestParameter(param) ||
|
||||
iife && parameters.length > iife.arguments.length && !type;
|
||||
if (!isOptionalParameter) {
|
||||
minArgumentCount = parameters.length;
|
||||
}
|
||||
@ -49601,7 +49606,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer);
|
||||
}
|
||||
}
|
||||
else if (isOptionalParameter(parameter)) {
|
||||
else if (hasEffectiveQuestionToken(parameter)) {
|
||||
seenOptionalParameter = true;
|
||||
if (parameter.questionToken && parameter.initializer) {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
|
||||
|
||||
@ -357,7 +357,6 @@ import {
|
||||
JSDocMemberName,
|
||||
JSDocOverloadTag,
|
||||
JSDocParameterTag,
|
||||
JSDocPropertyLikeTag,
|
||||
JSDocSatisfiesExpression,
|
||||
JSDocSatisfiesTag,
|
||||
JSDocSignature,
|
||||
@ -10485,7 +10484,7 @@ export function canHaveExportModifier(node: Node): node is Extract<HasModifiers,
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isOptionalJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag {
|
||||
export function isOptionalJSDocPropertyLikeTag(node: Node): boolean {
|
||||
if (!isJSDocPropertyLikeTag(node)) {
|
||||
return false;
|
||||
}
|
||||
@ -10514,7 +10513,7 @@ export function isJSDocOptionalParameter(node: ParameterDeclaration) {
|
||||
return isInJSFile(node) && (
|
||||
// node.type should only be a JSDocOptionalType when node is a parameter of a JSDocFunctionType
|
||||
node.type && node.type.kind === SyntaxKind.JSDocOptionalType
|
||||
|| getJSDocParameterTags(node).some(({ isBracketed, typeExpression }) => isBracketed || !!typeExpression && typeExpression.type.kind === SyntaxKind.JSDocOptionalType)
|
||||
|| getJSDocParameterTags(node).some(isOptionalJSDocPropertyLikeTag)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@
|
||||
// return curry(getStylingByKeys, 2)(mergedStyling, ...args);
|
||||
// ^^^^
|
||||
// | ----------------------------------------------------------------------
|
||||
// | (parameter) args: any
|
||||
// | (parameter) args: []
|
||||
// | ----------------------------------------------------------------------
|
||||
// },
|
||||
// 3
|
||||
@ -135,8 +135,12 @@
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "any",
|
||||
"kind": "keyword"
|
||||
"text": "[",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "]",
|
||||
"kind": "punctuation"
|
||||
}
|
||||
],
|
||||
"documentation": []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user