diff --git a/lib/rules/no-this-alias.js b/lib/rules/no-this-alias.js index a32f472..19fda9b 100644 --- a/lib/rules/no-this-alias.js +++ b/lib/rules/no-this-alias.js @@ -59,11 +59,10 @@ module.exports = { )[0]; return { - VariableDeclarator(node) { - const { id, init } = node; + "VariableDeclarator[init.type='ThisExpression']"(node) { + const { id } = node; - if (init.type !== "ThisExpression") return; - if (allowDestructuring && node.id.type !== "Identifier") return; + if (allowDestructuring && id.type !== "Identifier") return; if (!allowedNames.includes(id.name)) { context.report({ diff --git a/tests/lib/rules/no-this-alias.js b/tests/lib/rules/no-this-alias.js index f3ad295..ea09e8f 100644 --- a/tests/lib/rules/no-this-alias.js +++ b/tests/lib/rules/no-this-alias.js @@ -55,6 +55,12 @@ const [foo, bar] = this; }, ], }, + // https://github.com/bradzacher/eslint-plugin-typescript/issues/281 + ` +declare module 'foo' { + declare const aVar: string +} + `, ], invalid: [