# svelte/@typescript-eslint/no-unnecessary-condition

disallow conditionals where the type is always truthy or always falsy

  • ⚠️ This rule was deprecated. This rule is no longer needed when using svelte-eslint-parser>=v0.19.0.
  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

# 📖 Rule Details

This rule is no longer needed when using svelte-eslint-parser>=v0.19.0.

This rule extends the base @typescript-eslint’s @typescript-eslint/no-unnecessary-condition rule. The @typescript-eslint/no-unnecessary-condition rule does not understand reactive or rerendering of Svelte components and has false positives when used with Svelte components. This rule understands reactive and rerendering of Svelte components.

<script lang="ts">
  /* eslint svelte/@typescript-eslint/no-unnecessary-condition: "error" */
  export let foo: number | null = null;
  /* ✗ BAD */
  let b = foo || 42;
  /* ✓ GOOD */
  $: a = foo || 42;
</script>

<!-- ✓ GOOD -->
{foo || 42}

# 🔧 Options

{
  "@typescript-eslint/no-unnecessary-condition": "off",
  "svelte/@typescript-eslint/no-unnecessary-condition": [
    "error",
    {
      "allowConstantLoopConditions": false,
      "allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": false
    }
  ]
}

Same as @typescript-eslint/no-unnecessary-condition rule option. See here for details.

# 🚀 Version

This rule was introduced in eslint-plugin-svelte v2.9.0

# 🔍 Implementation

Taken with ❤️ from @typescript-eslint/eslint-plugin