Skip to content

Commit bff47d7

Browse files
authored
feat(eslint-plugin): [explicit-function-return-type] add support for typed class property definitions (typescript-eslint#8027)
1 parent 7fe657a commit bff47d7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ function ancestorHasReturnType(node: FunctionNode): boolean {
336336
return true;
337337
}
338338
break;
339+
case AST_NODE_TYPES.PropertyDefinition:
340+
if (ancestor.typeAnnotation) {
341+
return true;
342+
}
343+
break;
339344
}
340345

341346
ancestor = ancestor.parent;

packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,26 @@ let foo = (() => (() => {})())();
713713
},
714714
],
715715
},
716+
{
717+
code: `
718+
class Bar {
719+
bar: Foo = {
720+
foo: x => x + 1,
721+
};
722+
}
723+
`,
724+
},
725+
{
726+
code: `
727+
class Bar {
728+
bar: Foo[] = [
729+
{
730+
foo: x => x + 1,
731+
},
732+
];
733+
}
734+
`,
735+
},
716736
],
717737
invalid: [
718738
{
@@ -1651,6 +1671,26 @@ class Foo {
16511671
},
16521672
{
16531673
code: `
1674+
class Bar {
1675+
bar = [
1676+
{
1677+
foo: x => x + 1,
1678+
},
1679+
];
1680+
}
1681+
`,
1682+
errors: [
1683+
{
1684+
messageId: 'missingReturnType',
1685+
line: 5,
1686+
endLine: 5,
1687+
column: 7,
1688+
endColumn: 12,
1689+
},
1690+
],
1691+
},
1692+
{
1693+
code: `
16541694
const foo = (function () {
16551695
return 'foo';
16561696
})();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy