Skip to content

linter: react/exhaustive-deps: false positive when a variable is used as a type via "as" #20199

@akahoshi1421

Description

@akahoshi1421

What version of Oxlint are you using?

1.51.0

What command did you run?

npx oxlint

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": [],
  "categories": {
    "correctness": "off"
  },
  "env": {
    "builtin": true
  },
  "ignorePatterns": [
    "dist"
  ],
  "overrides": [
    {
      "files": [
        "src/*.{ts,tsx}"
      ],
      "rules": {
        "react/no-array-index-key": "error",
        "react/exhaustive-deps": "error",
        "jsx-a11y/img-redundant-alt": "error"
      },
      "globals": {
        "AudioWorkletGlobalScope": "readonly",
        "AudioWorkletProcessor": "readonly",
        "currentFrame": "readonly",
        "currentTime": "readonly",
        "registerProcessor": "readonly",
        "sampleRate": "readonly",
        "WorkletGlobalScope": "readonly"
      },
      "env": {
        "es2020": true,
        "browser": true
      },
      "plugins": [
        "react",
        "jsx-a11y"
      ]
    }
  ]
}

What happened?

react/exhaustive-deps incorrectly reports a missing dependency when a variable is used only as a type through as (e.g., as keyof typeof variable).

Example

import { useEffect, useState } from "react"

export const useTest = () => {
    const [state] = useState<Record<"a", string>>({
        a: "a",
    });

    useEffect(() => {
        const a = "a" as keyof typeof state;
        console.log(a);
    }, []);
    
    console.log(state);
}

Comparison with ESLint
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions