Skip to content

.call on an union with different arguments counts fails when passing any #58468

@nicolo-ribaudo

Description

@nicolo-ribaudo

🔎 Search Terms

call union expected arguments but got

🕗 Version & Regression Information

Before version 4.5 both the .calls in the example below failed. Since then, .call(null, something-not-any) is accepted and .call(null, something-any) failes.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-beta#code/CYUwxgNghgTiAEYD2A7AzgF3gMxQLngApCBKeAXgD54A3JAS2DIB8jCoCUBXAWwCMQMMlVoMmAKHGhIsBMnRYAHp14CYAbinhocRKkzwAngSgpDm8bgB0YKBAiFu9gDTxFJTddv3HXF0Y9JXEJDQOD3CyA

💻 Code

declare const fn: (() => void) | ((a: number) => void)

declare const x: number;
declare const y: any;

fn.call(null, x); // ok
fn.call(null, y); // error

fn(y); // ok
fn(x); // ok

🙁 Actual behavior

The line marked as // error gives the following error:

Expected 1 arguments, but got 2.

🙂 Expected behavior

It should be accepted, the same as the other lines are accepted.

Additional information about the issue

No response


TODO for myself: Remove @ts-ignore in https://github.com/babel/babel/blob/main/packages/babel-generator/src/printer.ts#L717 once this is fixed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions