Skip to content

Problem with @typescript-eslint/no-unnecessary-condition #111

@crisfcodes

Description

@crisfcodes

I'm using this code to validate if some hook is used inside an specific context but I obtain the following error: ESLint: Unnecessary conditional, value is always falsy.(@typescript-eslint/no-unnecessary-condition), what is the correct way to handle this, disabling the rule or is there another way?

import React from 'react'

import {AppStateContext} from '../components/containers'

export function useAppState() {
  const context = React.useContext(AppStateContext)

  if (!context) { // error comes from here
    throw new Error('useAppState must be used within the AppStateProvider')
  }

  return context
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions