Skip to content

Merging signatures using a union as rest parameters results in never.Β #47754

@jespertheend

Description

@jespertheend

Bug Report

πŸ”Ž Search Terms

merged parameters rest union never

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about union

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type RestParams = [y: string] | [y: number];

type Signature = (x: string, ...rest: RestParams) => void;

type MergedParams = Parameters<Signature>; // never

πŸ™ Actual behavior

MergedParams is of type never.

πŸ™‚ Expected behavior

MergedParams is of type [x: string, y: string] | [x: string, y: number]

I realise this can sort of be done by using [y: string | number] as type for RestParams. However, I'm using unions in parameters like this in order to overload the signatures of functions in jsdoc as shown here: #25590 (comment)
If I use a union like that it will show up as union in VSCode, instead of using the multiple signatures UI.
Here's an example of this: Playground link.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions