Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): [explicit-function-return-type] add support for typed class property definitions #8027

Merged
merged 1 commit into from Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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