Skip to content

Parameters<> helper only shows the last declared overloadΒ #54223

Closed
@m-gallesio

Description

@m-gallesio

Bug Report

πŸ”Ž Search Terms

Parameters, Overload

πŸ•— Version & Regression Information

5.0.4

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface X {
    a(x: string): void;
    a(x: number): void;
}

type T = Parameters<X["a"]>[0];

let n: T = 1; // works
let s: T = "a"; // ERROR: Type 'string' is not assignable to type 'number'

πŸ™ Actual behavior

When using the Parameters<T> helper type on a function with overloads, the resulting type considers only the very last overload.

I noticed this while trying to extract tpe type of the second argument of String.replace which can be both a string and a replacer function; only the replacer function is seen.

πŸ™‚ Expected behavior

I would expect the previous code to consider valid all types which can be used for the function's parameters.
In the given example T should be resolved as string | number.

Possibly related to #53541

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions