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
- id: C1 claim: "Template literals use template-string syntax at the type level." source: S1 evidence: "but are used in type positions"
- id: C2 claim: "Unions combine across interpolated positions." source: S1 evidence: "the unions are cross multiplied"
- id: C3 claim: "Literal unions can restrict a function to known argument values." source: S2 evidence: "functions that only accept a certain set of known values"
Sources
- [S1] Template literal types. Microsoft and TypeScript documentation contributors. https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html. CC-BY-4.0; license: https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE. Accessed 2026-11-05.
- [S2] Everyday types. Microsoft and TypeScript documentation contributors. https://www.typescriptlang.org/docs/handbook/2/everyday-types.html. CC-BY-4.0; license: https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE. Accessed 2026-11-05.
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
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.},
}
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.