# ...\` operator (template literal spreads)

**URL:** <https://es.discourse.group/t/operator-template-literal-spreads/2047>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [June 3, 2024, 6:06pm UTC](https://es.discourse.group/t/operator-template-literal-spreads/2047 "2024-06-03T18:06:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DerpMcDerp](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/derpmcderp/32/2102_2.png) [@DerpMcDerp](https://es.discourse.group/u/DerpMcDerp)\
**Post date:** [June 3, 2024, 6:06pm UTC](https://es.discourse.group/t/operator-template-literal-spreads/2047/1 "2024-06-03T18:06:45Z")

</div>

Template literal strings are almost useful. Here is how you can co-opt splat syntax to make template strings work the way that some people would prefer that it worked.

```javascript
foo(1, ...``, 2);
foo(1, ...`${a}`, 2);
foo(1, ...`${a}${b}`, 2);
foo(1, ...`Hello ${a} there ${b} world`, 2);
// syntax sugar for =>
foo(1, '', 2);
foo(1, a, 2); // as opposed to foo(1, '', a, '', 2);
foo(1, a, b, 2); // as opposed to foo(1, '', a, '', b, '', 2);
foo(1, "Hello ", a, " there ", b, " world", 2);

```

`...`something` ` is syntax sugar for `...internal_splat_helper`something` `:

```javascript
const internal_splat_helper = (template, ...rest) => {
	if (template.length === 1)
		return template;
	const ret = [];
	let i = 0;
	for (; i < rest.length; ++i) {
		if (template[i] !== '')
			ret.push(template[i]);
		ret.push(rest[i]);
	}
	if (template[i] !== '')
		ret.push(template[i]);
	return ret;
};

```

---

<div class="post-metadata">

**Author:** ![lightmare](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/lightmare/32/843_2.png) [@lightmare](https://es.discourse.group/u/lightmare)\
**Post date:** [June 4, 2024, 6:26am UTC](https://es.discourse.group/t/operator-template-literal-spreads/2047/2 "2024-06-04T06:26:29Z")

</div>

That's already valid syntax, `foo(...`bar`)` is effectively `foo(..."bar")` is `foo("b", "a", "r")`.

Besides, that `...splat`something` ` form looks workable, it's not that long and doesn't require learning another language feature.
