Skip to content

Inferring rest of array in a conditional results in unknown[] #45281

Open
@avaly

Description

@avaly

Bug Report

🔎 Search Terms

infer conditional array rest unknown

🕗 Version & Regression Information

  • I was unable to test this on prior versions than 4.1 because it uses template literal types added in 4.1

⏯ Playground Link

Playground link with relevant code

💻 Code

Using code from the #40336 description restricted to strings only:

type Join<S extends string[], D extends string> =
	S extends [] ? '' :
	S extends [string] ? `${S[0]}` :
	S extends [string, ...infer R] ? `${S[0]}${D}${Join<R, D>}` :
	string;

🙁 Actual behavior

R is inferred as being unknown[].

🙂 Expected behavior

R should be inferred as being string[].

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions