This content originally appeared on DEV Community and was authored by omkar garde
template literals types in typescript are built upon literal type.
a literal type represent that a variable can hold only one specific string.
a regular which can represent any string value.
let changingString = "Hello World";
changingString = "Goodbye World";
// Because `changingString` can represent any possible string, that
// is how TypeScript describes it in the type system
changingString;
const constantString = "Hello World";
// Because `constantString` can only represent 1 possible string, it
// has a literal type representation
// NOTE: literal types are still string and returned as such
constantString;
template literal or template which are delimited by backtick are used for.
- string interpolation
- exception function inline in string
- tagged template literal which are used to execute custom function
let a = 10;
console.log(`some string ${a}`)
console.log(`some string ${a+10}`)
a template literal is used to print out string to console while
template literal type are used for to represent a specific string value
This content originally appeared on DEV Community and was authored by omkar garde

omkar garde | Sciencx (2025-10-21T10:38:10+00:00) what are template literals types and what are template literals?. Retrieved from https://www.scien.cx/2025/10/21/what-are-template-literals-types-and-what-are-template-literals/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.