Skip to content

Commit 8c8497c

Browse files
committed
fix(eslint-plugin): [explicit-function-return-type] Fix obj setter prop
Fixes typescript-eslint#525
1 parent 1a0e60b commit 8c8497c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export default util.createRule<Options, MessageIds>({
6565
function isSetter(node: TSESTree.Node | undefined): boolean {
6666
return (
6767
!!node &&
68-
node.type === AST_NODE_TYPES.MethodDefinition &&
68+
(node.type === AST_NODE_TYPES.MethodDefinition ||
69+
node.type === AST_NODE_TYPES.Property) &&
6970
node.kind === 'set'
7071
);
7172
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ class App {
169169
`,
170170
options: [{ allowTypedFunctionExpressions: true }],
171171
},
172+
// https://github.com/typescript-eslint/typescript-eslint/issues/525
173+
{
174+
filename: 'test.ts',
175+
code: `
176+
const myObj = {
177+
set myProp(val) {
178+
this.myProp = val;
179+
},
180+
};
181+
`,
182+
},
172183
],
173184
invalid: [
174185
{

packages/typescript-estree/src/ts-estree/ts-estree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ export interface Property extends BaseNode {
895895
computed: boolean;
896896
method: boolean;
897897
shorthand: boolean;
898-
kind: 'init';
898+
kind: 'init' | 'get' | 'set';
899899
}
900900

901901
export interface RestElement extends BaseNode {

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