> ## 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 Generic Type Alias

A generic type alias is a parameterized type definition that accepts one or more type variables, enabling the creation of dynamic, reusable type blueprints. By appending type parameters enclosed in angle brackets (`<T>`) to a `type` declaration, the alias acts as a type-level function, substituting the provided type arguments into the alias's definition upon instantiation.

```typescript theme={"dark"}
type AliasName<TypeParameter1, TypeParameter2> = /* Definition using parameters */;
```

Unlike generic interfaces, which are restricted to defining object shapes, generic type aliases can resolve to any valid TypeScript type, including primitives, unions, intersections, tuples, and function signatures.

```typescript theme={"dark"}
// Resolving to a union type
type Nullable<T> = T | null | undefined;

// Resolving to a tuple type
type Pair<T, U> = [T, U];
```

## Type Constraints

Type parameters within an alias can be restricted using the `extends` keyword. This enforces a structural contract, ensuring that any type argument passed to the generic alias contains specific properties or matches a specific type signature.

```typescript theme={"dark"}
type Entity<T extends { id: string }> = T & { createdAt: Date };

// Valid: matches the constraint
type UserEntity = Entity<{ id: string; name: string }>; 

// Invalid: Type '{ name: string; }' does not satisfy the constraint '{ id: string; }'.
type InvalidEntity = Entity<{ name: string }>; 
```

## Default Type Arguments

Generic type aliases support default type parameters via the `=` operator. If a type argument is omitted during instantiation, the compiler falls back to the specified default type. Default parameters must appear after all required type parameters in the declaration.

```typescript theme={"dark"}
type ApiResponse<T, E = Error> = {
    success: boolean;
    data?: T;
    error?: E;
};

// Instantiation with both arguments
type CustomResponse = ApiResponse<string, TypeError>;

// Instantiation relying on the default argument (E resolves to Error)
type StandardResponse = ApiResponse<string>;
```

## Composition with Advanced Types

Generic type aliases are the foundational syntax for constructing TypeScript's advanced type mechanics, specifically conditional types and mapped types, as both require a type parameter to evaluate or iterate over.

**Conditional Types:**
A generic alias can use the ternary operator syntax to evaluate type relationships dynamically.

```typescript theme={"dark"}
type IsArray<T> = T extends any[] ? true : false;
```

**Mapped Types:**
A generic alias can iterate over the keys of a provided type parameter to transform its properties.

```typescript theme={"dark"}
type OptionalReadonly<T> = {
    readonly [K in keyof T]?: T[K];
};
```

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