From fe53d22f57ad418397fb31fa89c97db0ab4cd6c0 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 20 Oct 2021 00:52:39 -0700 Subject: [PATCH] fix(eslint-plugin): [typedef] fix regression with class properties (#4034) Fixes #4033 --- packages/eslint-plugin/src/rules/typedef.ts | 3 +-- .../eslint-plugin/tests/rules/typedef.test.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/src/rules/typedef.ts b/packages/eslint-plugin/src/rules/typedef.ts index 602df98e060..700fd347c77 100644 --- a/packages/eslint-plugin/src/rules/typedef.ts +++ b/packages/eslint-plugin/src/rules/typedef.ts @@ -175,8 +175,7 @@ export default util.createRule<[Options], MessageIds>({ ...(memberVariableDeclaration && { PropertyDefinition(node): void { if ( - !node.value || - !isVariableDeclarationIgnoreFunction(node.value) || + !(node.value && isVariableDeclarationIgnoreFunction(node.value)) && !node.typeAnnotation ) { report( diff --git a/packages/eslint-plugin/tests/rules/typedef.test.ts b/packages/eslint-plugin/tests/rules/typedef.test.ts index 09a4764a0ba..e237ff68636 100644 --- a/packages/eslint-plugin/tests/rules/typedef.test.ts +++ b/packages/eslint-plugin/tests/rules/typedef.test.ts @@ -442,6 +442,24 @@ class Foo { }, ], }, + // https://github.com/typescript-eslint/typescript-eslint/issues/4033 + { + code: ` +class ClassName { + public str: string = 'str'; + #num: number = 13; + + func: () => void = (): void => { + console.log(this.str); + }; +} + `, + options: [ + { + memberVariableDeclaration: true, + }, + ], + }, ], invalid: [ // Array destructuring