Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type-challenges-solutions/en/medium-join #238

Open
utterances-bot opened this issue Aug 2, 2022 · 2 comments
Open

type-challenges-solutions/en/medium-join #238

utterances-bot opened this issue Aug 2, 2022 · 2 comments

Comments

@utterances-bot
Copy link

Join

This project is aimed at helping you better understand how the type system works, writing your own utilities, or just having fun with the challenges.

https://ghaiklor.github.io/type-challenges-solutions/en/medium-join.html

Copy link

Beraliv commented Aug 2, 2022

Great job! Thank you for the article!

TIL: I really like the way you mention references at the end of the article, really helpful for people who are lost with the solution because of some missed TS feature or term

Copy link

Beraliv commented Aug 2, 2022

In case someone faces the problem with Type instantiation is excessively deep and possibly infinite, you will need to use Tail-Recursion Elimination on Conditional Types

The updated solution can look as following:

type JoinV2<T extends string[], U extends string | number, V extends string = ''> = T extends [
  infer S extends string,
  ...infer R extends string[]
]
  ? JoinV2<R, U, `${V}${V extends '' ? '' : U}${S}`>
  : V;

It also has its limitations around 998 recursive calls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants