From 1f4cab98e4f451b38e1c56878cbd6ade38238d0d Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Sun, 16 Jul 2017 15:47:56 -0700 Subject: [PATCH] Ignore children in propTypes --- .../react-js-make-props-and-state-transform.ts | 13 ++++++++++++- .../static-proptypes-many-props/input.tsx | 3 ++- .../static-proptypes-many-props/output.tsx | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/transforms/react-js-make-props-and-state-transform.ts b/src/transforms/react-js-make-props-and-state-transform.ts index 826f9d3..830275f 100644 --- a/src/transforms/react-js-make-props-and-state-transform.ts +++ b/src/transforms/react-js-make-props-and-state-transform.ts @@ -223,7 +223,18 @@ export function reactJSMakePropsAndStateInterfaceTransformFactoryFactory(typeChe return result; } const typeValue = getTypeFromReactPropTypeExpression(propertyAssignment.initializer); - const propertySignature = ts.createPropertySignature([], name, undefined, typeValue, undefined); + + // Ignore children, React types have it + if (propertyAssignment.name.getText() === 'children') { + return result; + } + const propertySignature = ts.createPropertySignature( + [], + name, + undefined, + typeValue, + undefined, + ); result.members.push(propertySignature) return result; }, ts.createTypeLiteralNode([])); diff --git a/test/react-js-make-props-and-state-transform/static-proptypes-many-props/input.tsx b/test/react-js-make-props-and-state-transform/static-proptypes-many-props/input.tsx index 02489c8..1e491c3 100644 --- a/test/react-js-make-props-and-state-transform/static-proptypes-many-props/input.tsx +++ b/test/react-js-make-props-and-state-transform/static-proptypes-many-props/input.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; export default class MyComponent extends React.Component { static propTypes = { + children: React.PropTypes.node, any: React.PropTypes.any, array: React.PropTypes.array, bool: React.PropTypes.bool, @@ -24,4 +25,4 @@ export default class MyComponent extends React.Component { render() { return
; } -} \ No newline at end of file +} diff --git a/test/react-js-make-props-and-state-transform/static-proptypes-many-props/output.tsx b/test/react-js-make-props-and-state-transform/static-proptypes-many-props/output.tsx index beaa5e4..89c5602 100644 --- a/test/react-js-make-props-and-state-transform/static-proptypes-many-props/output.tsx +++ b/test/react-js-make-props-and-state-transform/static-proptypes-many-props/output.tsx @@ -21,6 +21,7 @@ export default class MyComponent extends React.Component<{ elementRequired: JSX.Element; }, {}> { static propTypes = { + children: React.PropTypes.node, any: React.PropTypes.any, array: React.PropTypes.array, bool: React.PropTypes.bool,