diff --git a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts index f4c73ef0d9b..2214f8fa343 100644 --- a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts +++ b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts @@ -390,6 +390,10 @@ export default util.createRule({ function ancestorHasReturnType(node: FunctionNode): boolean { let ancestor = node.parent; + if (ancestor?.type === AST_NODE_TYPES.Property) { + ancestor = ancestor.value; + } + // if the ancestor is not a return, then this function was not returned at all, so we can exit early const isReturnStatement = ancestor?.type === AST_NODE_TYPES.ReturnStatement; diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index 25b70794843..b2906d17a98 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -661,6 +661,26 @@ export class A { b = A; } `, + ` +interface Foo { + f: (x: boolean) => boolean; +} + +export const a: Foo[] = [ + { + f: (x: boolean) => x, + }, +]; + `, + ` +interface Foo { + f: (x: boolean) => boolean; +} + +export const a: Foo = { + f: (x: boolean) => x, +}; + `, ], invalid: [ {