diff --git a/packages/eslint-plugin/src/rules/no-inferrable-types.ts b/packages/eslint-plugin/src/rules/no-inferrable-types.ts index 54823f7be39..f63beda7440 100644 --- a/packages/eslint-plugin/src/rules/no-inferrable-types.ts +++ b/packages/eslint-plugin/src/rules/no-inferrable-types.ts @@ -250,15 +250,19 @@ export default util.createRule({ if (ignoreParameters || !node.params) { return; } - ( - node.params.filter( - param => - param.type === AST_NODE_TYPES.AssignmentPattern && - param.left && - param.right, - ) as TSESTree.AssignmentPattern[] - ).forEach(param => { - reportInferrableType(param, param.left.typeAnnotation, param.right); + + node.params.forEach(param => { + if (param.type === AST_NODE_TYPES.TSParameterProperty) { + param = param.parameter; + } + + if ( + param.type === AST_NODE_TYPES.AssignmentPattern && + param.left && + param.right + ) { + reportInferrableType(param, param.left.typeAnnotation, param.right); + } }); } diff --git a/packages/eslint-plugin/tests/rules/no-inferrable-types.test.ts b/packages/eslint-plugin/tests/rules/no-inferrable-types.test.ts index ce1b5deb277..fe91490df3e 100644 --- a/packages/eslint-plugin/tests/rules/no-inferrable-types.test.ts +++ b/packages/eslint-plugin/tests/rules/no-inferrable-types.test.ts @@ -150,6 +150,13 @@ class Foo { a?: number = 5; b?: boolean = true; c?: string = 'foo'; +} + `, + }, + { + code: ` +class Foo { + constructor(public a = true) {} } `, }, @@ -289,5 +296,33 @@ class Foo { }, ], }, + { + code: ` +class Foo { + constructor(public a: boolean = true) {} +} + `, + output: ` +class Foo { + constructor(public a = true) {} +} + `, + options: [ + { + ignoreParameters: false, + ignoreProperties: false, + }, + ], + errors: [ + { + messageId: 'noInferrableType', + data: { + type: 'boolean', + }, + line: 3, + column: 22, + }, + ], + }, ], });