Generic type arguments in generic tagged templates

Tagged templates are a form of invocation introduced in ECMAScript 2015.Like call expressions, generic functions may be used in a tagged template and TypeScript will infer the type arguments utilized.

TypeScript 2.9 allows passing generic type arguments to tagged template strings.

Example

  1. declare function styledComponent<Props>(strs: TemplateStringsArray): Component<Props>;
  2. interface MyProps {
  3. name: string;
  4. age: number;
  5. }
  6. styledComponent<MyProps> `
  7. font-size: 1.5em;
  8. text-align: center;
  9. color: palevioletred;
  10. `;
  11. declare function tag<T>(strs: TemplateStringsArray, ...args: T[]): T;
  12. // inference fails because 'number' and 'string' are both candidates that conflict
  13. let a = tag<string | number> `${100} ${"hello"}`;