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