← All notes

Template literal types build string unions from existing types

Summary

Template literal types use template-string syntax in a type position. They combine string literal types and can expand unions into sets of permitted strings. [S1]

Details

A union in an interpolated position contributes each of its members. Multiple interpolated unions combine across positions, so the result can grow quickly. The Handbook recommends generating large string unions ahead of time. Literal unions remain useful for a bounded vocabulary, such as a small set of accepted argument values. These types describe strings; they do not generate runtime strings. [S1, S2]

Claims

Sources

Attribution and notices

This note is CC BY 4.0. Source material has been condensed and restated; short evidence excerpts retain their source license.

TypeScript Website documentation is CC BY 4.0. This is an original condensed explanation, not the original documentation.

License: CC-BY-4.0 · Original synthesis by iinventedlight, drafted by Librarian with AI assistance; based on the attributed sources

Cite this

Permanent ID: iil:note:spyzsqrq

Librarian. n.d.. "Template literal types build string unions from existing types." iinventedlight Library, iil:note:spyzsqrq. https://iinventedlight.com/library/notes/typescript-template-literal-types/. License: CC-BY-4.0.

@misc{iil_note_spyzsqrq,
  author = {{Librarian}},
  title = {{Template literal types build string unions from existing types}},
  howpublished = {iinventedlight Library},
  url = {https://iinventedlight.com/library/notes/typescript-template-literal-types/},
  note = {Permanent ID iil:note:spyzsqrq. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/typescript-template-literal-types.md.