From dcc0688142957226e60f548e61fbf20cf38baa6d Mon Sep 17 00:00:00 2001 From: heymdall Date: Wed, 28 Mar 2018 16:30:52 +0300 Subject: [PATCH] fix(component-typings): add proptypes types, mark all methods params as optional --- typings/stringify-component-definition.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/typings/stringify-component-definition.js b/typings/stringify-component-definition.js index 003019d..3497945 100644 --- a/typings/stringify-component-definition.js +++ b/typings/stringify-component-definition.js @@ -95,12 +95,13 @@ function stringifyObjectOf(type, componentName, propName, typeRefs) { function stringifyMethod({ name, docblock, params, description }) { // eslint-disable-line object-curly-newline return stringifyDescription(description, docblock) + // eslint-disable-line prefer-template - `${name}(${params.map(({ name }) => `${name}: any`).join(',')}): any;`; + `${name}(${params.map(({ name }) => `${name}?: any`).join(',')}): any;`; } function stringifyComponentDefinition(info) { const typeRefs = []; // PropType fields typedefs const propsInterfaceName = `${info.displayName}Props`; + const propTypesTypeName = `${info.displayName}PropTypes`; const propsDef = ( /* eslint-disable indent, object-curly-newline */ ` @@ -117,13 +118,17 @@ function stringifyComponentDefinition(info) { return ( ` import { Component, ReactNode } from 'react'; + import * as Type from 'prop-types'; ${typeRefs.join('\n')} ${propsDef} + + export type ${propTypesTypeName} = Record>; ${stringifyDescription(info.description, info.docblock)} export default class ${info.displayName} extends Component<${propsInterfaceName}, any> { + static propTypes: ${propTypesTypeName}; ${info.methods.map(stringifyMethod).join('')} } `