# @typescript-eslint/init-declarations

> Require or disallow a value in variable declarations

A variable declared without a value is `undefined` until a later line assigns it. If one branch skips the assignment, the code after it reads `undefined`. `"always"` requires a value in every declaration. `"never"` requires the opposite style: declare first, assign later.

It's the TypeScript version of `init-declarations`. A `declare let` and the variables in a `declare namespace` can't have a value, so `"always"` doesn't report them.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/init-declarations" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
# "always" or "never"
"@typescript-eslint/init-declarations" = ["error", "always"]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"options": ["always"]} */}
```ts
let discount: number;

if (isMember) {
  discount = 10;
}
```

Not reported:

{/* good {"options": ["always"]} */}
```ts
let discount = 0;

if (isMember) {
  discount = 10;
}

declare let isMember: boolean;
```

## Options

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/init-declarations" = ["error", "always"]
```

| Option | What it does |
| --- | --- |
| `"always"` | Report a `var` or `let` that has no value. |
| `"never"` | Report a `var` or `let` that has a value. `const` and `using` need one, so they're allowed. |

The default is `"always"`:

{/* bad */}
```ts
let discount: number;
```

With `"never"`:

{/* bad {"options": ["never"]} */}
```ts
let discount = 0;
```

{/* good {"options": ["never"]} */}
```ts
let discount: number;
const rate = 0.2;

discount = 100 * rate;
```

With `"never"`, a second option `{ "ignoreForLoopInit": true }` allows the variable in the head of a `for` loop. It's `false` by default.

{/* bad {"options": ["never"]} */}
```ts
for (let i = 0; i < 3; i++) {
  console.log(i);
}
```

{/* good {"options": ["never", {"ignoreForLoopInit": true}]} */}
```ts
for (let i = 0; i < 3; i++) {
  console.log(i);
}
```
