Visit complete TypeScript roadmap

← Back to Topics List

Template Literal Types

Template literal types in TypeScript are a way to manipulate string values as types. They allow you to create a type based on the result of string manipulation or concatenation. Template literal types are created using the backtick (“) character and string manipulation expressions within the type.

For example, the following is a template literal type that concatenates two strings:

type Name = `Mr. ` + string;

let name: Name = `Mr. Smith`;  // ok
let name: Name = `Mrs. Smith`;  // error

In this example, the Name template literal type is created by concatenating the string "Mr. " with the type string. This type can then be used to enforce that a value must be a string that starts with "Mr. ".

Learn more from the following links:

Community

roadmap.sh is the 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Roadmaps Best Practices Guides Videos Store YouTube

roadmap.sh by Kamran Ahmed

Community created roadmaps, articles, resources and journeys to help you choose your path and grow in your career.

© roadmap.sh · FAQs · Terms · Privacy

ThewNewStack

The leading DevOps resource for Kubernetes, cloud-native computing, and the latest in at-scale development, deployment, and management.