DEV Community

loading...

Discussion on: Fake tagged template string literal to enable syntax highlighting in VSCode

Collapse
iamarsenibragimov profile image
Arsen Ibragimov

Could you please explain what this line of code means?

const lit = (s: TemplateStringsArray, ...args: any[]) => s.map((ss, i) => ${ss}${args[i] || ''}).join('')

Collapse
patarapolw profile image
Pacharapol Withayasakpunt Author • Edited

It's literally what template string tags are -- functions.

You have to try this in your console.

function foo(...args) {
  console.log(JSON.stringify(args))
}

foo`a${1}b${2}c${3}d`

I get

[["a","b","c","d"],1,2,3]

The first arg is always an array of strings, and the latter args are objects, in their native form.