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

The `delete` operator is a unary operator that removes a specific own property from an object. Upon successful execution, the property is entirely detached from the object, and subsequent accesses to that property identifier will evaluate to `undefined`.

## Syntax

```typescript theme={"dark"}
delete object.property;
delete object["property"];
```

## Return Value

The operator evaluates to a `boolean`.

* Returns `true` if the property was successfully deleted, or if the property did not exist on the object in the first place.
* Returns `false` in JavaScript's runtime non-strict mode (or throws a `TypeError` in JavaScript's runtime strict mode via `"use strict"`) if the property is non-configurable, such as properties defined via `Object.defineProperty()` with `configurable: false`.

## TypeScript Type Checking

TypeScript enforces strict structural typing rules around the `delete` operator to prevent runtime mutations that violate an object's declared contract.

When the **`strictNullChecks`** compiler option is enabled (which is included when enabling the broader TypeScript `--strict` flag), the compiler requires that the operand of a `delete` operation be an **optional property**. Attempting to delete a required property results in compiler error **TS2790**. Furthermore, attempting to delete a property marked as `readonly` triggers compiler error **TS2794**, regardless of whether the property is optional or required.

```typescript theme={"dark"}
interface Entity {
  readonly id: string;  // Required, Read-only
  role: string;         // Required
  metadata?: string;    // Optional
}

const obj: Entity = {
  id: "123",
  role: "admin",
  metadata: "active"
};

delete obj.metadata; // Valid: Property is optional and mutable
delete obj.role;     // Error TS2790: The operand of a 'delete' operator must be optional.
delete obj.id;       // Error TS2794: The operand of a 'delete' operator cannot be a read-only property.
```

To bypass this for dynamic objects, the object must be typed with an index signature (e.g., `Record<string, any>` or `{[key: string]: unknown}`), which implicitly treats all properties as optional for deletion purposes.

## Mechanics and Limitations

* **Prototype Chain:** `delete` only operates on an object's *own* properties. It does not traverse the prototype chain. If an own property is deleted but a property with the same key exists on the prototype, the prototype's property will be exposed upon subsequent lookups.
* **Variables and Functions:** The operator cannot delete variables declared with `var`, `let`, or `const`, nor can it delete standalone function declarations. It strictly targets object properties.
* **Arrays:** When applied to an array index, `delete` removes the value at that specific index but does *not* mutate the array's `length` property or shift subsequent elements. This creates a sparse array containing an `empty` slot.

```typescript theme={"dark"}
const sequence: number[] = [10, 20, 30];
delete sequence[1];

console.log(sequence.length); // 3
console.log(sequence);        // [10, empty, 30]
console.log(sequence[1]);     // undefined
```

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