mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-16 15:51:35 -05:00
fix(53011): Illegal declaration file can be emitted (duplicate parameter names) when spreading tuples into parameter positions (#53028)
This commit is contained in:
@@ -12644,11 +12644,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
|
||||
function expandSignatureParametersWithTupleMembers(restType: TupleTypeReference, restIndex: number) {
|
||||
const elementTypes = getTypeArguments(restType);
|
||||
const associatedNames = restType.target.labeledElementDeclarations;
|
||||
const associatedNames = getUniqAssociatedNamesFromTupleType(restType);
|
||||
const restParams = map(elementTypes, (t, i) => {
|
||||
// Lookup the label from the individual tuple passed in before falling back to the signature `rest` parameter name
|
||||
const tupleLabelName = !!associatedNames && getTupleElementLabel(associatedNames[i]);
|
||||
const name = tupleLabelName || getParameterNameAtPosition(sig, restIndex + i, restType);
|
||||
const name = associatedNames && associatedNames[i] ? associatedNames[i] :
|
||||
getParameterNameAtPosition(sig, restIndex + i, restType);
|
||||
const flags = restType.target.elementFlags[i];
|
||||
const checkFlags = flags & ElementFlags.Variable ? CheckFlags.RestParameter :
|
||||
flags & ElementFlags.Optional ? CheckFlags.OptionalParameter : 0;
|
||||
@@ -12658,6 +12658,22 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
});
|
||||
return concatenate(sig.parameters.slice(0, restIndex), restParams);
|
||||
}
|
||||
|
||||
function getUniqAssociatedNamesFromTupleType(type: TupleTypeReference) {
|
||||
const associatedNamesMap = new Map<__String, number>();
|
||||
return map(type.target.labeledElementDeclarations, labeledElement => {
|
||||
const name = getTupleElementLabel(labeledElement);
|
||||
const prevCounter = associatedNamesMap.get(name);
|
||||
if (prevCounter === undefined) {
|
||||
associatedNamesMap.set(name, 1);
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
associatedNamesMap.set(name, prevCounter + 1);
|
||||
return `${name}_${prevCounter}` as __String;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaultConstructSignatures(classType: InterfaceType): Signature[] {
|
||||
|
||||
Reference in New Issue
Block a user