Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73a63ee

Browse files
authored
fix(eslint-plugin): [explicit-module-boundary-types] ignore functions exported within typed object/array literals (typescript-eslint#2805)
1 parent 32b1b68 commit 73a63ee

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ export default util.createRule<Options, MessageIds>({
390390
function ancestorHasReturnType(node: FunctionNode): boolean {
391391
let ancestor = node.parent;
392392

393+
if (ancestor?.type === AST_NODE_TYPES.Property) {
394+
ancestor = ancestor.value;
395+
}
396+
393397
// if the ancestor is not a return, then this function was not returned at all, so we can exit early
394398
const isReturnStatement =
395399
ancestor?.type === AST_NODE_TYPES.ReturnStatement;

packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,26 @@ export class A {
661661
b = A;
662662
}
663663
`,
664+
`
665+
interface Foo {
666+
f: (x: boolean) => boolean;
667+
}
668+
669+
export const a: Foo[] = [
670+
{
671+
f: (x: boolean) => x,
672+
},
673+
];
674+
`,
675+
`
676+
interface Foo {
677+
f: (x: boolean) => boolean;
678+
}
679+
680+
export const a: Foo = {
681+
f: (x: boolean) => x,
682+
};
683+
`,
664684
],
665685
invalid: [
666686
{

0 commit comments

Comments
 (0)