Skip to content

Commit

Permalink
fix(eslint-plugin): [explicit-module-boundary-types] fixes #2864 rela…
Browse files Browse the repository at this point in the history
…ted to functions in nested object properties (#3178)
  • Loading branch information
grumd committed Mar 15, 2021
1 parent 1a96426 commit 55e1fba
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts
Expand Up @@ -52,11 +52,12 @@ function isConstructorArgument(
}

/**
* Checks if a node belongs to:
* Checks if a node is a property or a nested property of a typed object:
* ```
* const x: Foo = { prop: () => {} }
* const x = { prop: () => {} } as Foo
* const x = <Foo>{ prop: () => {} }
* const x: Foo = { bar: { prop: () => {} } }
* ```
*/
function isPropertyOfObjectWithType(
Expand All @@ -82,7 +83,8 @@ function isPropertyOfObjectWithType(
isTypeAssertion(parent) ||
isClassPropertyWithTypeAnnotation(parent) ||
isVariableDeclaratorWithTypeAnnotation(parent) ||
isFunctionArgument(parent)
isFunctionArgument(parent) ||
isPropertyOfObjectWithType(parent)
);
}

Expand Down
Expand Up @@ -156,6 +156,34 @@ const x = <Foo>{
code: `
const x: Foo = {
foo: () => {},
};
`,
options: [{ allowTypedFunctionExpressions: true }],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/2864
{
filename: 'test.ts',
code: `
const x = {
foo: { bar: () => {} },
} as Foo;
`,
options: [{ allowTypedFunctionExpressions: true }],
},
{
filename: 'test.ts',
code: `
const x = <Foo>{
foo: { bar: () => {} },
};
`,
options: [{ allowTypedFunctionExpressions: true }],
},
{
filename: 'test.ts',
code: `
const x: Foo = {
foo: { bar: () => {} },
};
`,
options: [{ allowTypedFunctionExpressions: true }],
Expand Down
Expand Up @@ -181,6 +181,34 @@ export const x = <Foo>{
code: `
export const x: Foo = {
foo: () => {},
};
`,
options: [{ allowTypedFunctionExpressions: true }],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/2864
{
filename: 'test.ts',
code: `
export const x = {
foo: { bar: () => {} },
} as Foo;
`,
options: [{ allowTypedFunctionExpressions: true }],
},
{
filename: 'test.ts',
code: `
export const x = <Foo>{
foo: { bar: () => {} },
};
`,
options: [{ allowTypedFunctionExpressions: true }],
},
{
filename: 'test.ts',
code: `
export const x: Foo = {
foo: { bar: () => {} },
};
`,
options: [{ allowTypedFunctionExpressions: true }],
Expand Down

0 comments on commit 55e1fba

Please sign in to comment.