diff --git a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts index a8030da1bfb..512ff62202b 100644 --- a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts +++ b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts @@ -336,6 +336,11 @@ function ancestorHasReturnType(node: FunctionNode): boolean { return true; } break; + case AST_NODE_TYPES.PropertyDefinition: + if (ancestor.typeAnnotation) { + return true; + } + break; } ancestor = ancestor.parent; diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index eedbd9b76c7..8b0a05d6b5b 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -713,6 +713,26 @@ let foo = (() => (() => {})())(); }, ], }, + { + code: ` +class Bar { + bar: Foo = { + foo: x => x + 1, + }; +} + `, + }, + { + code: ` +class Bar { + bar: Foo[] = [ + { + foo: x => x + 1, + }, + ]; +} + `, + }, ], invalid: [ { @@ -1651,6 +1671,26 @@ class Foo { }, { code: ` +class Bar { + bar = [ + { + foo: x => x + 1, + }, + ]; +} + `, + errors: [ + { + messageId: 'missingReturnType', + line: 5, + endLine: 5, + column: 7, + endColumn: 12, + }, + ], + }, + { + code: ` const foo = (function () { return 'foo'; })();