From 02f5b3a094f4e10c0bec012e6f4ad938521926c1 Mon Sep 17 00:00:00 2001 From: Dimava Date: Thu, 26 Feb 2026 11:02:46 +0300 Subject: [PATCH] fix(linter): ignore unresolved type-only initializer references Prevent no-use-before-define from reporting unresolved references in initializers when ignoreTypeReferences is enabled, so type assertions like `x as foo` are not treated as value self-references. Made-with: Cursor --- .../src/rules/eslint/no_use_before_define.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/oxc_linter/src/rules/eslint/no_use_before_define.rs b/crates/oxc_linter/src/rules/eslint/no_use_before_define.rs index 4b7177b4b2d9d..7097fa9bf1ade 100644 --- a/crates/oxc_linter/src/rules/eslint/no_use_before_define.rs +++ b/crates/oxc_linter/src/rules/eslint/no_use_before_define.rs @@ -132,6 +132,9 @@ impl Rule for NoUseBeforeDefine { } let Some(symbol_id) = reference.symbol_id() else { + if self.0.ignore_type_references && is_type_reference(reference, node, ctx) { + return; + } if let Some(declaration_span) = unresolved_initializer_reference_declaration_span(identifier, node, ctx) { @@ -2508,6 +2511,19 @@ fn test_typescript_eslint() { ", Some(serde_json::json!([{ "ignoreTypeReferences": true }])), ), + ( + " + declare global { + type foo = string; + } + + export function fn(x: unknown) { + const foo = x as foo; + return foo; + } + ", + Some(serde_json::json!([{ "ignoreTypeReferences": true, "variables": true }])), + ), ( " namespace A.X.Y {}