Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@m-gallesio

Description

@m-gallesio
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.