TSadvancedts-evergreen

Template literal types

String types you can compute.

Template literal types apply backtick interpolation at the type level — ` on${Capitalize<E>} ` — letting the compiler build, constrain, and even parse string types from other types instead of treating every string the same.

A greeting type with a literal placeholder

TSintro
Press Run to execute

greet('Ada') returns "Hello, Ada!" and greet('world') returns "Hello, world!" — the same literal shape the Greeting<T> type encodes, so the runtime builder's return type is the template literal type itself, not a loose string.