我被困在Typescript 编译不断失败的部分.
以下是代码:
(currentCellData.ellipsis && currentCellData.renderValue.props.children ? (
<NTooltip key={index} title={currentCellData.renderValue} arrow placement="top-start">
{renderTableCell}
</NTooltip>
) : (
<Fragment key={index}>{renderTableCell}</Fragment>
))
这是renderValue
的数据和类型.
declare type TValue = {
renderValue: string | React.ReactElement;
onClick?: (e: React.MouseEvent<HTMLTableCellElement>) => void;
ellipsis?: boolean;
};
我想在renderValue
内的props
个属性中得到children
的值.
然而,当我激活打字脚本编译时,它失败并给出消息
src/components/NTableBody/index.tsx:110:68 - error TS2339: Property 'props' does not exist on type 'string | ReactElement<any, string | JSXElementConstructor<any>>'.
Property 'props' does not exist on type 'string'.
我认为问题出在renderValue
类型的字符串定义上.但是,其他组件也需要字符串定义.
如何解决或绕过此类型问题?