Skip to content

linter: ignoreTypeReferences not applied when variable name matches global type name #19743

@Dimava2

Description

@Dimava2

What version of Oxlint are you using?

1.50.0

What command did you run?

oxlint --type-aware repro/oxlint-ignore-type-refs.ts

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

Minimal config (verified to reproduce):

{
  "rules": {
    "no-use-before-define": ["error", { "ignoreTypeReferences": true, "variables": true }]
  }
}

What happened?

With ignoreTypeReferences: true, type-only references (e.g. in as TypeName casts) should be ignored by no-use-before-define. However, when a variable has the same name as a type, oxlint incorrectly treats the type reference as a variable reference.

Repro steps:

  1. Create a .ts file with the code below
  2. Create .oxlintrc.json with the config above
  3. Run oxlint --type-aware -c .oxlintrc.json <file>.ts
declare global {
  type foo = string
}

export function fn(x: unknown) {
  const foo = x as foo   // 'as foo' is a type reference, not variable
  return foo
}

Expected: No error. The as foo is a type-only reference and should be ignored per ignoreTypeReferences: true.

Actual: Oxlint reports:

eslint(no-use-before-define): 'foo' was used before it was defined.
  const foo = x as foo
        ^^^      ^^^
         |        `-- used here
         `-- defined here

Oxlint conflates the type foo (in as foo) with the variable foo being declared, treating the type assertion as a use of the variable before its definition.

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