I am relatively new to TypeScript and am reviewing both documentación oficial
the GitHub
.
In one of these GitHub examples there is a function uri
that passes arguments without using parentheses ( ejemplo completo
):
public async getRateLimit() {
return this.get<RateLimit>(uri`/rate_limit`);
}
Here is the implementation of this function:
function uri(template: TemplateStringsArray, ...args: any[]): string;
function uri(template: TemplateStringsArray) {
let text = template[0];
for (let i = 1; i < template.length; i++) {
text += encodeURIComponent(String(arguments[i]));
text += template[i];
}
return text;
}
I can't see this way of calling functions documented anywhere. I would really appreciate a link to the documentation or an explanation if I'm wrong.
This is not a Typescript feature as such but an ECMAScript 6 feature called tagged template literals .
Typescript developers usually try to support native language features as much as possible since Typescript always compiles to javascript so it would not be a good idea to remove features from the base language. This is a quote from an old news story but it gives you an idea of the goals of the language developers and in which version that change occurred.