You can get close, but there's a problem: unions don't really have an order you can rely on. The compiler is fully within its rights to rearrange if it wants to. There's also some other weird cases with unions as well. I recommend looking at this answer by Jcalz about how to turn a union into a tuple for more details and pitfalls: https://stackoverflow.com/a/55128956/3794812

If we can change your requirements so the starting point is a tuple (eg, ['foo', 'bar', 'baz']) we'll be able to do it with no problem. But if you must start with a union, then we have to do a hacky and unreliable conversion from union to tuple. Which you shouldn't do. Seriously, see Jcalz's answer for all the reasons why you shouldn't do it.


Step 1: Utility to split a tuple into its Head and Tail

The plan is to take the tuple of strings and recursively join them together. To do that, i need to be able to break off the head ("foo", for the first step) and the tail (["bar", "baz"]). The head is easy, that's just T[0], where T is the tuple. For the tail, we have this utility type:

type Tail<T extends string[]> = T extends [string, ...infer TailType] ? TailType : never;

Step 2: Recursively do the joining

The following type takes in a string (H for "head"), an array of strings (T for "tail"), and a string for the separator. If the array has exactly one string in it, then the result is just to join them together with the separator, as in {Separator}${T[0]}. If there's more than one string, we need to recursively repeat the process, joining the head with whatever we get by joining the tail together

type JoinRecursive<H extends string, T extends string[], Separator extends string> = 
  Tail<T> extends [string, ...string[]] 
    ? `{Separator}${JoinRecursive<T[0], Tail<T>>}` 
    : `{Separator}${T[0]}`

Step 3: Provide an entry point

The recursive generic expects it to already be split into a head and a tail, so for convenience, i'll make a Join type that can take in the string tuple directly, and then will do that first split:

type Join<T extends string[], Separator extends string> = 
  Tail<T> extends string[] 
    ? JoinRecursive<T[0], Tail<T>, Separator> 
    : T[0];

Putting it together:

And here's how it then gets used:

type UnionTuple = ['foo', 'bar', 'baz'];
// If you must start from a union, the best that can be done is
//   Jcalz's TuplifyUnion hack. But don't do this.
// type UnionStr = 'foo' | 'bar' | 'baz';
// type UnionTuple = TuplifyUnion<UnionStr>;

type Test = Join<UnionTuple, ','> // 'foo,bar,baz'
type Test2 = Join<UnionTuple, '*'> // 'foo*bar*baz'

Playground link

Answer from Nicholas Tower on Stack Overflow
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ typescript โ€บ typescript_array_join.htm
TypeScript - Array join()
join() method joins all the elements of an array into a string. separator โˆ’ Specifies a string to separate each element of the array. If omitted, the array elements are separated with a comma.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ typescript-array-join-method
TypeScript Array join() Method - GeeksforGeeks
July 12, 2024 - The Array.join() method in TypeScript is a built-in function used to join all the elements of an array into a single string. This method is particularly useful when you need to concatenate array elements with a specific separator.
๐ŸŒ
SPGuides
spguides.com โ€บ typescript-array-to-string-with-separator
How to Convert Typescript Array to String With Separator? โ€“ Learn SharePoint, Microsoft Power Platform and SPFx Tutorials โ€“ SPGuides
July 21, 2025 - The join method in TypeScript is ... returns a new array with the same items as the original array. By using the join method on the new array, to convert it to a string with the separator between each item....
Top answer
1 of 1
1

You can get close, but there's a problem: unions don't really have an order you can rely on. The compiler is fully within its rights to rearrange if it wants to. There's also some other weird cases with unions as well. I recommend looking at this answer by Jcalz about how to turn a union into a tuple for more details and pitfalls: https://stackoverflow.com/a/55128956/3794812

If we can change your requirements so the starting point is a tuple (eg, ['foo', 'bar', 'baz']) we'll be able to do it with no problem. But if you must start with a union, then we have to do a hacky and unreliable conversion from union to tuple. Which you shouldn't do. Seriously, see Jcalz's answer for all the reasons why you shouldn't do it.


Step 1: Utility to split a tuple into its Head and Tail

The plan is to take the tuple of strings and recursively join them together. To do that, i need to be able to break off the head ("foo", for the first step) and the tail (["bar", "baz"]). The head is easy, that's just T[0], where T is the tuple. For the tail, we have this utility type:

type Tail<T extends string[]> = T extends [string, ...infer TailType] ? TailType : never;

Step 2: Recursively do the joining

The following type takes in a string (H for "head"), an array of strings (T for "tail"), and a string for the separator. If the array has exactly one string in it, then the result is just to join them together with the separator, as in {Separator}${T[0]}. If there's more than one string, we need to recursively repeat the process, joining the head with whatever we get by joining the tail together

type JoinRecursive<H extends string, T extends string[], Separator extends string> = 
  Tail<T> extends [string, ...string[]] 
    ? `{Separator}${JoinRecursive<T[0], Tail<T>>}` 
    : `{Separator}${T[0]}`

Step 3: Provide an entry point

The recursive generic expects it to already be split into a head and a tail, so for convenience, i'll make a Join type that can take in the string tuple directly, and then will do that first split:

type Join<T extends string[], Separator extends string> = 
  Tail<T> extends string[] 
    ? JoinRecursive<T[0], Tail<T>, Separator> 
    : T[0];

Putting it together:

And here's how it then gets used:

type UnionTuple = ['foo', 'bar', 'baz'];
// If you must start from a union, the best that can be done is
//   Jcalz's TuplifyUnion hack. But don't do this.
// type UnionStr = 'foo' | 'bar' | 'baz';
// type UnionTuple = TuplifyUnion<UnionStr>;

type Test = Join<UnionTuple, ','> // 'foo,bar,baz'
type Test2 = Join<UnionTuple, '*'> // 'foo*bar*baz'

Playground link

๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-concatenate-strings-with-separator
Concatenate Strings with a Separator using JavaScript | bobbyhadz
March 3, 2024 - To concatenate strings with a separator, add the strings to an array and call the `join()` method on the array, passing it the separator as a parameter.
๐ŸŒ
DEV Community
dev.to โ€บ ncpa0cpl โ€บ typescript-concatenate-multiple-string-literals-c59
TypeScript string literal type concatenation - DEV Community
July 1, 2022 - In the TypeScript version 4.7 and upwards the Concat utility type can be simplified like so: export type Concat<T extends string[]> = T extends [ infer F extends string, ...infer R extends string[] ] ? `${F}${Concat<R>}` : ''; And here's a join function and Concat utility type with a separator: export type PrependIfDefined<T extends string, S extends string> = T extends "" ?
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-join-method-of-an-array-in-typescript
What is the join() method of an array in TypeScript?
... separator: This is a character or string that separates each element of the array when joined as a string. This method returns the combination of all the elements of the array as a single string.
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 15-4-ways-to-combine-strings
4 Ways to Combine Strings in JavaScript | SamanthaMing.com
You can do this by passing a separator in its parameter. const array = ['My handles are']; const handles = [instagram, twitter, tiktok].join(', '); // @samanthaming, @samantha_ming, @samanthaming array.push(handles); // ['My handles are', ...
Find elsewhere
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ join
Array.prototype.join() - JavaScript - MDN Web Docs
The join() method of Array instances returns a new string that is the concatenation of all elements in this array, separated by commas or a specified separator string. If the array has only one item, that item's stringification is returned without using the separator.
๐ŸŒ
xjavascript
xjavascript.com โ€บ blog โ€บ typescript-join-array-of-strings
Mastering String Array Joining in TypeScript โ€” xjavascript.com
You can also specify a custom separator when using the join method. For instance, if you want to separate the strings with a hyphen (-):
๐ŸŒ
Webdevtutor
webdevtutor.net โ€บ blog โ€บ typescript-string-join-with-comma
How to Use TypeScript's String Join Method with Comma Separation
The join() method in TypeScript is a part of the String.prototype object. It takes an optional separator as an argument and returns a new string that concatenates all the elements of the provided array or iterable, using the specified separator. To join strings with commas in TypeScript, you ...
๐ŸŒ
xjavascript
xjavascript.com โ€บ blog โ€บ typescript-array-to-string-with-separator
TypeScript Array to String with Separator: A Comprehensive Guide โ€” xjavascript.com
The join() method creates and returns a new string by concatenating all of the elements in an array, separated by a specified separator string.
๐ŸŒ
Webdevtutor
webdevtutor.net โ€บ blog โ€บ typescript-join-with-comma
How to Join Strings with Comma in TypeScript
function joinWithComma(strings: string[]): string { return strings.reduce((prev, current) => `${prev}, ${current}`); } const fruits: string[] = ["apple", "banana", "orange"]; const result: string = joinWithComma(fruits); console.log(result); // Output: "apple, banana, orange" Template literals in TypeScript provide a convenient way to interpolate values within strings.
๐ŸŒ
Java Guides
javaguides.net โ€บ 2025 โ€บ 01 โ€บ typescript-array-join.html
TypeScript Array join()
January 4, 2025 - The elements are separated by a specified separator string. If no separator is provided, a comma (,) is used by default. ... separator (optional): A string to separate each pair of adjacent elements of the array.
๐ŸŒ
daily.dev
daily.dev โ€บ home โ€บ blog โ€บ webdev โ€บ javascript join() method: syntax, examples & pitfalls
JavaScript join() Method: Syntax, Examples & Pitfalls | daily.dev
May 25, 2026 - The Array join() method converts arrays to strings with a custom separator. Covers syntax, handling null/undefined, performance in loops
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ TypedArray โ€บ join
TypedArray.prototype.join() - JavaScript - MDN Web Docs
The join() method of TypedArray instances returns a new string that is the concatenation of all elements in this typed array, separated by commas or a specified separator string. If the typed array has only one item, that item's stringification is returned without using the separator.
๐ŸŒ
DEV Community
dev.to โ€บ jrcharney โ€บ split-and-join-the-dichotomy-of-strings-and-arrays-2hb
Split and Join: The Dichotomy of Strings and Arrays - DEV Community
December 19, 2022 - Strings and Arrays are like Yin and Yang. You use .split() to split an string into an array. You use .join() to join arrays into strings.