From f27288c2dc473424224571d28fdd18844fefaaa9 Mon Sep 17 00:00:00 2001 From: Hank Chen Date: Thu, 24 Sep 2020 09:37:15 +0800 Subject: [PATCH] [Fix] `prop-types`: handle RestElement in destructured param --- lib/rules/prop-types.js | 3 +++ tests/lib/rules/prop-types.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index ee939df065..6eec874a89 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -150,6 +150,9 @@ module.exports = { return; } param.properties.forEach((property) => { + if (property.type === 'RestElement') { + return; + } const type = property.value.type; const right = property.value.right; if (type !== 'AssignmentPattern') { diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index b68dafe534..0ef8a072f0 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -3109,6 +3109,40 @@ ruleTester.run('prop-types', rule, { type StateProps = ReturnType type DispatchProps = ReturnType`, parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + import React from 'react' + + interface Meta { + touched: boolean, + error: string; + } + + interface Props { + input: string, + meta: Meta, + cssClasses: object + } + const InputField = ({ input, meta: { touched, error }, cssClasses = {}, ...restProps }: Props) => { + restProps.className = cssClasses.base + + if (cssClasses.custom) { + restProps.className += 'cssClasses.custom' + } + if (touched && error) { + restProps.className += 'cssClasses.error' + } + + return( + + ) + } + export default InputField`, + parser: parsers['@TYPESCRIPT_ESLINT'] } ]) ),