Can TaggedTempalte have overload signatures with a certain string literal argument?

Viewed 156
declare function taggedFn(x: ['strange']): 123;
declare function taggedFn(x: TemplateStringsArray): string;

// OK
var v1: string = taggedFn`ordinary`;

// NG: How can I hit the ['strange'] signature?
var v2: 123 = taggedFn`strange`;
  • I have a TaggedTemplate function
  • I can control its signatures
  • I want it to return string on a normal call
  • I want it to return 123 when a argument is strange (NG)

Basically it's possible for a normal function by overloading but how can we with TaggedTemplate function? Is it possible to overload it with a certain argument?

Here's a working example.

Thanks.

1 Answers

This is currently not possible and there is an open issue in TS issue tracker to add support for this.

Related