0

So recently I have stumbled upon syntax that is new to me in Typescript eg:

someFunction`Literal template goes here`

no parantesis, no nothing. As a result function someFunction is called. Does it have some sort of name? Why paranthesis is not required here? Why it does not work for eg string?

Complete code and working (sort of) example

function test(v:ReadonlyArray<string>){
  console.log(v);
  console.log(v.length);
}

function test2(v:Readonly<string>){
  console.log(v);
}


console.log("gonna do it");

test`and iv done it
really done it!`;

test2"something else??"; // does not work

TSPlayground

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • Does this answer your question? [What does this symbol mean in JavaScript?](https://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript) (specifically the bit which says "What is the purpose of template literals (backticks) following a function in ES6?") – Quentin May 26 '22 at 14:46
  • Thank you very much!. So much to learn yet – Antoniossss May 26 '22 at 14:53

0 Answers0