> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript Template Literal Type

Template literal types are string types constructed by interpolating other types within backticks (`` ` ``). They resolve to exact string literal types at compile time and, when combined with union types, automatically generate a Cartesian product of all possible string combinations.

## Basic Interpolation

The syntax mirrors JavaScript template literals but operates strictly at the type level. You can interpolate `string`, `number`, `bigint`, `boolean`, `null`, and `undefined`.

```typescript theme={"dark"}
type Prefix = "app";
type Version = 1;
type Identifier = `${Prefix}_v${Version}`; 
// Type: "app_v1"
```

## Union Expansion (Cartesian Product)

When a union type is interpolated within a template literal type, TypeScript distributes the operation across the union members. If multiple unions are interpolated, TypeScript computes the cross-multiplication (Cartesian product) of all sets.

```typescript theme={"dark"}
type Size = "small" | "large";
type Color = "red" | "blue";

type ProductID = `${Size}-${Color}`;
// Type: "small-red" | "small-blue" | "large-red" | "large-blue"
```

## Intrinsic String Manipulation Types

TypeScript provides four intrinsic utility types implemented directly in the compiler to transform string literal types within template literals:

* `Uppercase<StringType>`: Converts all characters to uppercase.
* `Lowercase<StringType>`: Converts all characters to lowercase.
* `Capitalize<StringType>`: Converts the first character to uppercase.
* `Uncapitalize<StringType>`: Converts the first character to lowercase.

```typescript theme={"dark"}
type Action = "update" | "delete";

type ActionConstant = `ACTION_${Uppercase<Action>}`;
// Type: "ACTION_UPDATE" | "ACTION_DELETE"

type HandlerMethod = `on${Capitalize<Action>}`;
// Type: "onUpdate" | "onDelete"
```

## Pattern Matching with `infer`

Template literal types can be used within conditional types to perform pattern matching and substring extraction using the `infer` keyword. TypeScript infers the narrowest possible string literal type that satisfies the structural pattern.

```typescript theme={"dark"}
type ExtractDomain<T extends string> = T extends `${string}@${infer Domain}` ? Domain : never;

type DomainType = ExtractDomain<"admin@example.com">; 
// Type: "example.com"
```

Multiple `infer` declarations can be used sequentially to deconstruct complex string literal types into individual type variables.

```typescript theme={"dark"}
type SplitTuple<T extends string> = T extends `${infer Left}_${infer Right}` 
  ? [Left, Right] 
  : never;

type Parts = SplitTuple<"foo_bar">; 
// Type: ["foo", "bar"]
```

## Broad String Interpolation

If a generic `string` or `number` type is interpolated rather than a specific literal, the resulting template literal type represents an infinite set of strings matching that pattern.

```typescript theme={"dark"}
type EventName = `on${string}`;

const validEvent: EventName = "onClick";    // OK
const invalidEvent: EventName = "click";    // Error: Type '"click"' is not assignable to type '`on${string}`'
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor TypeScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
