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

The `++` (increment) operator is a unary mutating operator that increments its operand by a value of one. In TypeScript, the operand must be a valid l-value (such as a mutable variable or property) explicitly typed as or inferred to be `number`, `bigint`, or `any`.

The operator operates in two distinct syntactic positions, dictating its evaluation order relative to the return value:

**Postfix Increment (`operand++`)**
The expression evaluates to the *original* value of the operand before the mutation occurs. The increment operation is applied to the underlying memory reference as a side effect after the original value is yielded.

```typescript theme={"dark"}
let postfixValue: number = 10;
let postfixResult: number = postfixValue++; 

// postfixResult === 10 (evaluated before increment)
// postfixValue === 11 (mutated after evaluation)
```

**Prefix Increment (`++operand`)**
The expression mutates the operand first, and then evaluates to the *newly incremented* value.

```typescript theme={"dark"}
let prefixValue: number = 10;
let prefixResult: number = ++prefixValue; 

// prefixValue === 11 (mutated before evaluation)
// prefixResult === 11 (evaluated after increment)
```

**TypeScript Compiler Constraints**
Unlike JavaScript, which attempts implicit type coercion at runtime, TypeScript's static type checker enforces strict constraints on the `++` operator during compilation:

1. **Type Safety:** The operand must be assignable to a valid arithmetic type. Applying `++` to a `string`, `boolean`, or `unknown` yields a compile-time error.
   ```typescript theme={"dark"}
   ```

let str: string = "5";
str++; // Error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.

````
2. **Enum Assignability:** While an `enum` is recognized as a valid arithmetic operand (avoiding `TS2356`), applying `++` to an enum variable in TypeScript 5.0+ results in an assignment error. The increment operation produces a `number`, which is no longer implicitly assignable back to a modern union enum type.
   ```typescript
enum Status { Pending = 1 }
let currentStatus: Status = Status.Pending;
currentStatus++; // Error TS2322: Type 'number' is not assignable to type 'Status'.
````

3. **Mutability:** The operand must be a mutable reference. Applying `++` to a `const` variable or a `readonly` property results in an assignment error.
   ```typescript theme={"dark"}
   ```

const immutableValue: number = 1;
immutableValue++; // Error TS2588: Cannot assign to 'immutableValue' because it is a constant.

````
4. **BigInt Compatibility:** When applied to a `bigint`, the operator increments the value by `1n` rather than `1`. The operand must be strictly typed as `bigint` to prevent mixed-type arithmetic errors.
   ```typescript
let bigValue: bigint = 100n;
bigValue++; // Evaluates to 100n, bigValue becomes 101n
````

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