Skip to content

Commit

Permalink
fix(component-typings): add proptypes types, mark all methods params …
Browse files Browse the repository at this point in the history
…as optional
  • Loading branch information
Heymdall committed Mar 28, 2018
1 parent 55a55a4 commit dcc0688
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion typings/stringify-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
`
Expand All @@ -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<keyof ${propsInterfaceName}, Type.Validator<${propsInterfaceName}>>;
${stringifyDescription(info.description, info.docblock)}
export default class ${info.displayName} extends Component<${propsInterfaceName}, any> {
static propTypes: ${propTypesTypeName};
${info.methods.map(stringifyMethod).join('')}
}
`
Expand Down

0 comments on commit dcc0688

Please sign in to comment.