{"record":{"id":"c47b54e4669d8945","repo":"oxc-project/oxc","slug":"unexpected-aliasing-of-this-to-local-variable","errorCode":null,"errorMessage":"Unexpected aliasing of 'this' to local variable.","messagePattern":"Unexpected aliasing of 'this' to local variable\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/typescript/no_this_alias.rs","lineNumber":20,"sourceCode":"    AstKind,\n    ast::{AssignmentTarget, BindingPattern, Expression, match_simple_assignment_target},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\nuse rustc_hash::FxHashSet;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_this_alias_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected aliasing of 'this' to local variable.\")\n        .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.\")\n        .with_label(span)\n}\n\nfn no_this_destructure_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected aliasing of members of 'this' to local variables.\")\n        .with_help(\n            \"Disabling destructuring of this is not a default, consider allowing destructuring\",\n        )\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoThisAlias(Box<NoThisAliasConfig>);\n\n#[derive(Debug, Clone, JsonSchema, Serialize, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoThisAliasConfig {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_this_alias.rs#L2-L38","documentation":"Raised by typescript/no_this_alias when `this` is assigned to a local variable (e.g. `const self = this`). At the throw site the alias exists to preserve `this` inside a nested regular function — a pre-arrow-function workaround; in TypeScript/ES2015+ an arrow function preserves lexical `this` and removes the need for the alias, which also defeats some type narrowing. no_this_alias_diagnostic fires from run() on assignment targets bound to the ThisExpression.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/typescript/no_this_alias.rs:20 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the alias with an arrow function to preserve `this`.","Use function.bind(this) where a callback needs the this value.","Add an allowDestructuring/allowedNames exception if the alias is deliberate."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}