I am trying to use an ES5 template tagged literal with typescript, but it looks like the script type does not have full support for This. I have the following code.
class TemplateLiterals {
age: number = 24;
name: 'Luke Skywalker'
private tag(strings: string[], personExp, ageExp) :string{
var str0 = strings[0];
var str1 = strings[1];
var ageStr;
if (ageExp > 99) {
ageStr = 'centenarian';
} else {
ageStr = 'youngster';
}
return str0 + personExp + str1 + ageStr;
}
toString() {
return this.tag `that ${ this.name } is a ${ this.age }`;
}
}
The toString
typescript method shows me the following error.
Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string[]'.
Property 'push' is missing in type 'TemplateStringsArray'.
I do not know why this showed me this error. According to mozilla's document, "The first argument to a tag function contains an array of string values." Therefore, it must accept an array of strings. But the actual expectation is TemplateStringsArray
. You donโt know how and when it is determined interface
TemplateSringsArray
. I am currently using type TemplateSringsArray
to avoid this error. Can anyone explain what is happening. Thank you Here is a playground .