oxc-project/oxc · error · OxcDiagnostic

Unexpected aliasing of members of 'this' to local variables.

Error message

Unexpected aliasing of members of 'this' to local variables.

What it means

Raised by typescript/no_this_alias when destructuring from `this` into local variables (e.g. `const { a, b } = this;`). At the throw site members of `this` are detached into locals — the plural form of the this-aliasing pattern — which snapshot mutable instance state at that instant and can desynchronize from the instance; the rule directs authors to keep member access explicit or use arrow functions. no_this_destructure_diagnostic fires from run() on destructuring declarations whose right side is `this`.

Source

Thrown at crates/oxc_linter/src/rules/typescript/no_this_alias.rs:26

use oxc_str::CompactStr;
use rustc_hash::FxHashSet;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    rule::{DefaultRuleConfig, Rule},
};

fn no_this_alias_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected aliasing of 'this' to local variable.")
        .with_help("Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES2015 practices or not managing scope well.")
        .with_label(span)
}

fn no_this_destructure_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected aliasing of members of 'this' to local variables.")
        .with_help(
            "Disabling destructuring of this is not a default, consider allowing destructuring",
        )
        .with_label(span)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct NoThisAlias(Box<NoThisAliasConfig>);

#[derive(Debug, Clone, JsonSchema, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoThisAliasConfig {
    /// Whether to allow destructuring of `this` to local variables.
    allow_destructuring: bool,
    /// An array of variable names that are allowed to alias `this`.
    #[serde(alias = "allowNames")]
    // Note: allowedNames is the config option used in the original ESLint rule, we typo'd it as allowNames.
    allowed_names: FxHashSet<CompactStr>,

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Access members directly through this.x instead of destructuring.
  2. Enable allowDestructuring in rule options if this pattern is acceptable.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/no_this_alias.rs:26 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/61839a66f2220a54. Report an issue: GitHub.