mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Improved parameter names for call signatures resulting from unions when only one parameter name is available. (#32056)
This commit is contained in:
parent
fbdbb141a2
commit
d2c9d6cc1b
@ -7247,9 +7247,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
function combineUnionParameters(left: Signature, right: Signature) {
|
||||
const longest = getParameterCount(left) >= getParameterCount(right) ? left : right;
|
||||
const leftCount = getParameterCount(left);
|
||||
const rightCount = getParameterCount(right);
|
||||
const longest = leftCount >= rightCount ? left : right;
|
||||
const shorter = longest === left ? right : left;
|
||||
const longestCount = getParameterCount(longest);
|
||||
const longestCount = longest === left ? leftCount : rightCount;
|
||||
const eitherHasEffectiveRest = (hasEffectiveRestParameter(left) || hasEffectiveRestParameter(right));
|
||||
const needsExtraRestElement = eitherHasEffectiveRest && !hasEffectiveRestParameter(longest);
|
||||
const params = new Array<Symbol>(longestCount + (needsExtraRestElement ? 1 : 0));
|
||||
@ -7259,11 +7261,16 @@ namespace ts {
|
||||
const unionParamType = getIntersectionType([longestParamType, shorterParamType]);
|
||||
const isRestParam = eitherHasEffectiveRest && !needsExtraRestElement && i === (longestCount - 1);
|
||||
const isOptional = i >= getMinArgumentCount(longest) && i >= getMinArgumentCount(shorter);
|
||||
const leftName = getParameterNameAtPosition(left, i);
|
||||
const rightName = getParameterNameAtPosition(right, i);
|
||||
const leftName = i >= leftCount ? undefined : getParameterNameAtPosition(left, i);
|
||||
const rightName = i >= rightCount ? undefined : getParameterNameAtPosition(right, i);
|
||||
|
||||
const paramName = leftName === rightName ? leftName :
|
||||
!leftName ? rightName :
|
||||
!rightName ? leftName :
|
||||
undefined;
|
||||
const paramSymbol = createSymbol(
|
||||
SymbolFlags.FunctionScopedVariable | (isOptional && !isRestParam ? SymbolFlags.Optional : 0),
|
||||
leftName === rightName ? leftName : `arg${i}` as __String
|
||||
paramName || `arg${i}` as __String
|
||||
);
|
||||
paramSymbol.type = isRestParam ? createArrayType(unionParamType) : unionParamType;
|
||||
params[i] = paramSymbol;
|
||||
|
||||
@ -34,6 +34,14 @@
|
||||
//// ;
|
||||
////
|
||||
////callableThing4(/*4*/);
|
||||
////
|
||||
////declare const callableThing5:
|
||||
//// | (<U>(a1: U) => void)
|
||||
//// | (() => void)
|
||||
//// ;
|
||||
////
|
||||
////callableThing5(/*5*/1)
|
||||
////
|
||||
|
||||
verify.signatureHelp({
|
||||
marker: "1",
|
||||
@ -50,4 +58,8 @@ verify.signatureHelp({
|
||||
{
|
||||
marker: "4",
|
||||
text: "callableThing4(arg0: { x: number; } & { y: number; } & { z: number; } & { u: number; } & { v: number; } & { w: number; }): void"
|
||||
},
|
||||
{
|
||||
marker: "5",
|
||||
text: "callableThing5(a1: number): void"
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user