> ## 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 Indexed Access Type

An indexed access type (often referred to as a lookup type) is a TypeScript mechanism used to retrieve the type of a specific property or a set of properties from another type. It allows developers to dynamically reference the type of a property by using bracket notation, operating strictly at the type level rather than the value level.

## Syntax

```typescript theme={"dark"}
type ExtractedType = TargetType[IndexType];
```

* **`TargetType`**: The object, array, or tuple type being queried.
* **`IndexType`**: The type representing the key(s) to look up. This can be a string, numeric, or symbol literal type, a union of literal types, a primitive type (such as `string` or `number` when accessing index signatures or arrays), or a generic type parameter (e.g., `K extends keyof T`).

## Mechanics and Behavior

### 1. Single Property Extraction

When `IndexType` is a single literal type, the resulting type is the exact type of that specific property on the `TargetType`.

```typescript theme={"dark"}
type Configuration = {
  endpoint: string;
  timeout: number;
  secure: boolean;
};

type TimeoutType = Configuration["timeout"]; 
// Result: number
```

### 2. Union Type Extraction

If `IndexType` is a union of types, TypeScript evaluates the lookup for each member of the union and returns a union of the corresponding property types.

```typescript theme={"dark"}
type EndpointOrSecure = Configuration["endpoint" | "secure"]; 
// Result: string | boolean
```

### 3. Exhaustive Extraction via `keyof`

Combining an indexed access type with the `keyof` operator extracts a union type representing all possible value types within the `TargetType`.

```typescript theme={"dark"}
type AllConfigurationValues = Configuration[keyof Configuration]; 
// Result: string | number | boolean
```

### 4. Array and Tuple Extraction

Indexed access types can be applied to arrays and tuples using numeric literal types or the primitive `number` type.

* **Tuples**: Indexing with a specific numeric literal extracts the type at that exact position.
* **Arrays/Tuples**: Indexing with the primitive `number` type extracts a union of all possible element types within the array or tuple.

```typescript theme={"dark"}
type DataTuple = [string, number, boolean];

type FirstElement = DataTuple[0]; 
// Result: string

type AnyTupleElement = DataTuple[number]; 
// Result: string | number | boolean

type StringArray = string[];
type ArrayElement = StringArray[number]; 
// Result: string
```

## Strict Type Constraints

The `IndexType` passed into the brackets must be a valid type that exists as a key or index signature on the `TargetType`.

1. **Invalid indices yield errors**: Attempting to use a type that cannot index the target type will result in a compiler error (`Type 'X' cannot be used to index type 'Y'`).
2. **Values cannot be used as indices**: You cannot pass a runtime variable into an indexed access type unless you extract its type using the `typeof` operator.

```typescript theme={"dark"}
const key = "timeout";

// ERROR: 'key' refers to a value, but is being used as a type here.
type InvalidLookup = Configuration[key]; 

// VALID: Extracts the literal type "timeout" from the constant value.
type ValidLookup = Configuration[typeof key]; 
```

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