> ## 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 Required Parameter

In TypeScript, a required parameter is a function parameter that mandates an argument to be passed during invocation. By default, every parameter defined in a TypeScript function signature is required. The compiler enforces strict arity, ensuring the number of provided arguments exactly matches the number of required parameters defined in the signature.

```typescript theme={"dark"}
function initializeNode(id: string, retries: number): void {
    // Implementation
}

initializeNode("node_01", 3); // Valid
initializeNode("node_01");    // Error: Expected 2 arguments, but got 1.
```

## Structural and Compiler Rules

**1. Arity and Type Enforcement**
When a function is invoked, the compiler checks both the arity (argument count) and the type compatibility. Omitting an argument for a required parameter, or providing an argument of the wrong type, results in a compile-time error (`ts(2554)` or `ts(2345)`).

**2. Positional Constraints**
In a function signature, required parameters must strictly precede any optional parameters (denoted by `?`) or rest parameters (denoted by `...`). A required parameter cannot follow an optional parameter because it creates ambiguity during positional argument resolution.

```typescript theme={"dark"}
// INVALID: A required parameter cannot follow an optional parameter.
function configureInvalid(timeout?: number, mode: string): void {} 
// Error: A required parameter cannot follow an optional parameter.

// VALID: Required parameters are declared first.
function configureValid(mode: string, timeout?: number): void {}
```

**3. Interaction with `strictNullChecks`**
A required parameter dictates that an argument *must* be provided, but it does not inherently dictate that the value cannot be `undefined`. If a parameter must be provided but is allowed to be `undefined`, it must be typed with a union type.

Even if the type accepts `undefined`, the parameter remains structurally required; the invocation cannot be empty.

```typescript theme={"dark"}
function setThreshold(value: number | undefined): void {
    // Implementation
}

setThreshold(10);        // Valid
setThreshold(undefined); // Valid: Argument is explicitly provided and matches type.
setThreshold();          // Error: Expected 1 arguments, but got 0.
```

**4. Default Parameters and Required Arity**
While assigning a default value (e.g., `param: type = value`) typically makes a parameter optional, this behavior changes based on positional context. If a default-initialized parameter precedes a required parameter, it is **not** treated as optional for the purpose of function application. The caller is strictly required to pass an argument (typically `undefined` to trigger the default value) for that position to satisfy the arity of the subsequent required parameter.

```typescript theme={"dark"}
function setup(mode = "auto", timeout: number): void {
    // Implementation
}

setup(undefined, 5000); // Valid: 'mode' defaults to "auto", 'timeout' is 5000.
setup(5000);            // Error: Expected 2 arguments, but got 1.
```

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