Revert changes for template literal types, keeping tests. by DanielRosenwasser · Pull Request #42588 · microsoft/TypeScript (original) (raw)

Yeah, we had a lot of mixed feedback. I will say about half the team really wanted this and another half felt uneasy about it. We got feedback from existing projects that inferring template literal types by default was questionable at best.

Even though the original concern was about combinatoric explosions of string types, I think in the future we might be open to inferring literal strings when they can be constructed, but not necessarily template string types.

For example

function foo(x: "a" | "b") const str = hello ${x}; // "a" | "b" }

but not

function foo(x: string) const str = hello <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi><mi mathvariant="normal">‘</mi><mo separator="true">;</mo><mi mathvariant="normal">/</mi><mi mathvariant="normal">/</mi><mi mathvariant="normal">‘</mi><mi>h</mi><mi>e</mi><mi>l</mi><mi>l</mi><mi>o</mi></mrow><annotation encoding="application/x-tex">{x}; // hello </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span></span><span class="mord">‘</span><span class="mpunct">;</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">//‘</span><span class="mord mathnormal">h</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">o</span></span></span></span>{string} }