Skip to content

Instantly share code, notes, and snippets.

@stepancar
Created May 25, 2017 00:31
Show Gist options
  • Save stepancar/78c0911e01bd948ced04d54e1cc7a86c to your computer and use it in GitHub Desktop.
Save stepancar/78c0911e01bd948ced04d54e1cc7a86c to your computer and use it in GitHub Desktop.
function getDtsContent(doc) {
console.log(doc.props)
return (`
import { Component } from 'react';
${doc.composes.map(({ componentName, filePath }) =>
`import { ${componentName}Props } from './${path.relative(path.dirname(doc.filePath), filePath )}'`
)}
export interface ${doc.componentName}Props ${doc.composes.length > 0? `extends ${doc.composes.map(({componentName}) => `${componentName}Props`).join(' & ')}`: ''}{
${Object.keys(doc.props).map(propName => {
const { required, type } = doc.props[propName];
return `${propName}${required? '': '?'}: ${type.name}`;
})}
}
export default class ${doc.componentName} extends React.Component<${doc.componentName}Props, any>{
${doc.methods.map(({ name, docblock, params, description }) =>
`${name}(${params.map(({ name }) =>
`${name}: any`).join(', ')
}): any;`
)}
}
`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment