init-declarations
Added in v0.8.1Configuration
Rule Details
Require or disallow initialization in variable declarations.
This rule applies to var, let, const, using, and await using declarations. It reports each declarator whose initialization does or does not match the configured mode.
Examples of incorrect code for this rule with "always" (the default):
Examples of correct code for this rule with "always":
Examples of incorrect code for this rule with "never":
Examples of correct code for this rule with "never":
const, using, and await using declarations always require an initializer, so "never" never flags them.
Examples of correct code for this rule with { "ignoreForLoopInit": true }:
A destructuring declarator (var { a } = obj;, var [a] = arr;) is never reported, in either mode.
declare var/declare let/declare const, and any declaration nested inside a declare namespace/declare module/ambient .d.ts context, is exempt in both modes.
Options
This rule takes up to two options:
- A string, either
"always"(default) or"never". - When the first option is
"never", an object with:ignoreForLoopInit: whentrue, allows initialization in aforloop's declaration even under"never". Defaultfalse.