8000 Inferred type incomplete, when inferring parameters type on surcharged constructors. Β· Issue #59812 Β· microsoft/TypeScript Β· GitHub
[go: up one dir, main page]

Skip to content
Inferred type incomplete, when inferring parameters type on surcharged constructors.Β #59812
Closed
@denis-migdal

Description

@denis-migdal

πŸ”Ž Search Terms

None

πŸ•— Version & Regression Information

Tested on the nightly build.

⏯ Playground Link

tsx function foo(a: boolean): void function foo(a: number): void function foo(a: boolean|number) {} type InferArgs<T> = T extends (...args: infer U) => void ? U : never; type Args = InferArgs<typeof foo... Playground Link

πŸ’» Code

function foo(a: boolean): void
function foo(a: number): void
function foo(a: boolean|number) {}

type InferArgs<T> = T extends (...args: infer U) => void ? U : never;

type Args = InferArgs<typeof foo>;

let a: Args = [true];

πŸ™ Actual behavior

When inferring the function parameters, only one of the function signature is used.
Here, Args is [number], which raises an error in the last line.

πŸ™‚ Expected behavior

When inferring the function parameters, the union of the different signatures should be returned.
Here, Args should be [number]|[boolean].

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    UnactionableThere isn't something we can do with this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0