We have a component like:
import PropTypes from 'prop-types';
import React from 'react';
export default class Tooltip extends React.Component {
static propTypes = {
/**
* Some children components
*/
children: PropTypes.node.isRequired,
/**
* Some property
*/
someProp: PropTypes.string,
}
.....
}
Is there some tooling to enable type generation to a typescript declaration file to generate something like:
interface ITooltip {
children: React.Node,
someProp: string
}
Some reference:
If you install
@types/prop-types
you can use theInferProps
generic type to generate types like that:The type is more verbose due to typings of
prop-types
, but it gives you the correct result in usage.