mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
Preserve arity for preserving js optional parameters (#37173)
This commit is contained in:
@@ -10510,7 +10510,7 @@ namespace ts {
|
||||
const signature = getSignatureFromDeclaration(node.parent);
|
||||
const parameterIndex = node.parent.parameters.indexOf(node);
|
||||
Debug.assert(parameterIndex >= 0);
|
||||
return parameterIndex >= getMinArgumentCount(signature);
|
||||
return parameterIndex >= getMinArgumentCount(signature, /*strongArityForUntypedJS*/ true);
|
||||
}
|
||||
const iife = getImmediatelyInvokedFunctionExpression(node.parent);
|
||||
if (iife) {
|
||||
@@ -10601,6 +10601,9 @@ namespace ts {
|
||||
isValueSignatureDeclaration(declaration) &&
|
||||
!hasJSDocParameterTags(declaration) &&
|
||||
!getJSDocType(declaration);
|
||||
if (isUntypedSignatureInJSFile) {
|
||||
flags |= SignatureFlags.IsUntypedSignatureInJSFile;
|
||||
}
|
||||
|
||||
// If this is a JSDoc construct signature, then skip the first parameter in the
|
||||
// parameter list. The first parameter represents the return type of the construct
|
||||
@@ -10631,7 +10634,6 @@ namespace ts {
|
||||
const isOptionalParameter = isOptionalJSDocParameterTag(param) ||
|
||||
param.initializer || param.questionToken || param.dotDotDotToken ||
|
||||
iife && parameters.length > iife.arguments.length && !type ||
|
||||
isUntypedSignatureInJSFile ||
|
||||
isJSDocOptionalParameter(param);
|
||||
if (!isOptionalParameter) {
|
||||
minArgumentCount = parameters.length;
|
||||
@@ -26375,7 +26377,7 @@ namespace ts {
|
||||
return length;
|
||||
}
|
||||
|
||||
function getMinArgumentCount(signature: Signature) {
|
||||
function getMinArgumentCount(signature: Signature, strongArityForUntypedJS?: boolean) {
|
||||
if (signatureHasRestParameter(signature)) {
|
||||
const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]);
|
||||
if (isTupleType(restType)) {
|
||||
@@ -26385,6 +26387,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strongArityForUntypedJS && signature.flags & SignatureFlags.IsUntypedSignatureInJSFile) {
|
||||
return 0;
|
||||
}
|
||||
return signature.minArgumentCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -4817,6 +4817,7 @@ namespace ts {
|
||||
HasLiteralTypes = 1 << 1, // Indicates signature is specialized
|
||||
IsInnerCallChain = 1 << 2, // Indicates signature comes from a CallChain nested in an outer OptionalChain
|
||||
IsOuterCallChain = 1 << 3, // Indicates signature comes from a CallChain that is the outermost chain of an optional expression
|
||||
IsUntypedSignatureInJSFile = 1 << 4, // Indicates signature is from a js file and has no types
|
||||
|
||||
// We do not propagate `IsInnerCallChain` to instantiated signatures, as that would result in us
|
||||
// attempting to add `| undefined` on each recursive call to `getReturnTypeOfSignature` when
|
||||
|
||||
Reference in New Issue
Block a user