> ## 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 Default Type Parameter

A default type parameter in TypeScript allows a generic type, interface, class, or function to specify a fallback type for a generic parameter. If the consumer of the generic does not explicitly provide a type argument and the compiler cannot infer one from the context, TypeScript automatically assigns the default type.

## Syntax

The default type is assigned using the `=` operator within the generic angle brackets `< >`.

```typescript theme={"dark"}
<T = DefaultType>
<T extends ConstraintType = DefaultType>
```

## Rules and Mechanics

When defining default type parameters, the TypeScript compiler enforces strict structural rules:

**1. Ordering and Cascading Defaults**
Required type parameters must strictly precede optional (defaulted) type parameters. Once a default type is declared for a parameter, all subsequent type parameters in the generic list must also be initialized with a default type.

```typescript theme={"dark"}
// Valid: Required parameter 'T' precedes defaulted parameter 'U'
type Pair<T, U = boolean> = { first: T, second: U };

// Invalid: Required parameter 'U' follows defaulted parameter 'T'
// Error: Required type parameters may not follow optional type parameters.
type InvalidPair<T = string, U> = { first: T, second: U }; 
```

**2. Constraint Satisfaction**
If a type parameter is bounded by a constraint using the `extends` keyword, the default type must strictly satisfy that constraint.

```typescript theme={"dark"}
// Valid: 'string' satisfies the 'string | number' constraint
type Identifier<T extends string | number = string> = { id: T };

// Invalid: 'boolean' does not satisfy the 'string | number' constraint
// Error: Type 'boolean' does not satisfy the constraint 'string | number'.
type InvalidIdentifier<T extends string | number = boolean> = { id: T }; 
```

**3. Forward Referencing**
A default type parameter can reference preceding type parameters declared within the same generic list. It cannot reference type parameters declared after it.

```typescript theme={"dark"}
// Valid: 'U' defaults to whatever type is resolved for 'T'
type Transformer<T, U = T> = {
    input: T;
    output: U;
};

let identity: Transformer<number>; // T = number, U = number
let cast: Transformer<number, string>; // T = number, U = string
```

## Resolution Order

When the TypeScript compiler processes a generic invocation, it resolves the type parameter in the following order:

1. **Explicit Assignment:** The type explicitly passed in the angle brackets (e.g., `Container<number>`).
2. **Inference:** The type inferred from the function arguments or assignment context.
3. **Default Type:** The fallback type defined by the `=` operator in the generic declaration.
4. **Constraint Fallback:** If no default exists and inference fails, it falls back to the constraint type (if `extends` is used) or `unknown`/`{}`.

<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>
