Skip to content

Commit

Permalink
feat(eslint-plugin): [explicit-function-return-type] add support for …
Browse files Browse the repository at this point in the history
…typed class property definitions (#8027)
  • Loading branch information
auvred committed Dec 5, 2023
1 parent 7fe657a commit bff47d7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts
Expand Up @@ -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;
Expand Down
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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';
})();
Expand Down

0 comments on commit bff47d7

Please sign in to comment.