import { ReactElement , ReactNode } from 'react' ; interface InnerText { ( jsx ) : string ; default : InnerText ; } const hasProps = ( jsx ) : jsx is ReactElement => Object . prototype . hasOwnProperty . call ( jsx , 'props' ) ; const reduceJsxToString = ( previous , current ) : string => previous + innerText ( current ) ; const innerText = ( jsx ) : string => { if ( jsx === null || typeof jsx === 'boolean' || typeof jsx === 'undefined' ) { return '' ; } if ( typeof jsx === 'number' ) { return jsx . toString ( ) ; } if ( typeof jsx === 'string' ) { return jsx ; } if ( Array . isArray ( jsx ) ) { return jsx . reduce < string > ( reduceJsxToString , '' ) ; } if ( hasProps ( jsx ) && Object . prototype . hasOwnProperty . call ( jsx . props , 'children' ) ) { return innerText ( jsx . props . children ) ; } return '' ; } ; innerText . default = innerText ; export = innerText ;