> ## 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 Auto-Accessor Field

An auto-accessor field is a class property declaration prefixed with the `accessor` keyword that automatically generates a private backing field along with a corresponding getter and setter pair on the class prototype. Introduced to align TypeScript with the ECMAScript Class Accessors proposal, it provides a standardized mechanism for property interception, specifically designed to be targeted by class decorators.

## Syntax

The `accessor` modifier is placed before the property name, optionally accompanied by a type annotation and an initial value.

```typescript theme={"dark"}
class Entity {
    accessor identifier: string = "unassigned";
}
```

## Underlying Mechanics

When the TypeScript compiler processes an auto-accessor, it desugars the single declaration into three distinct components:

1. A private, uniquely named backing field on the class instance.
2. A `get` method on the class prototype.
3. A `set` method on the class prototype.

Conceptually, the previous syntax is transpiled to the following equivalent structure:

```typescript theme={"dark"}
class Entity {
    // 1. Private backing field (instance-bound)
    #identifier: string = "unassigned";

    // 2. Prototype getter
    get identifier(): string {
        return this.#identifier;
    }

    // 3. Prototype setter
    set identifier(value: string) {
        this.#identifier = value;
    }
}
```

## Technical Characteristics

* **Memory Allocation:** Unlike standard class fields which are defined directly on the instance (`this.propertyName`), the auto-accessor defines its getter and setter on the prototype chain. Only the hidden backing field consumes per-instance memory.
* **Initialization Phase:** The default value assigned to an auto-accessor is evaluated and bound to the private backing field during the instance initialization phase, immediately prior to the execution of the constructor body.
* **Decorator Metadata:** When a decorator is applied to an `accessor` field, the decorator's context receives a `ClassAccessorDecoratorContext`. Instead of receiving a standard property descriptor, the decorator receives an object containing `get` and `set` functions. This allows the decorator to wrap or mutate the accessor logic directly without needing to manually redefine the property descriptor using `Object.defineProperty`.

## Interface Implementation

Auto-accessors satisfy interface requirements identically to standard properties or explicit getter/setter pairs. The interface only dictates the public contract, remaining agnostic to the underlying `accessor` implementation.

```typescript theme={"dark"}
interface IEntity {
    identifier: string;
}

class User implements IEntity {
    // Satisfies the interface contract via prototype accessors
    accessor identifier: string;
    
    constructor(id: string) {
        this.identifier = id;
    }
}
```

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