如何求解是指一个值,但在这里用作类型。您的意思是"日期选择器类型"吗?



我将ReactJs与TypeScript和AntDesign一起使用,但我遇到了问题。

我得到了返回AntDesignComponent的函数,但typeScript抛出错误。

"TextArea"指的是一个值,但在此处用作类型。你是说"文本区类型"吗?ts(2749(

算术运算的左侧必须是"any"、"number"、"bigint"或枚举类型。ts(2362(

算术运算的左侧必须是"any"、"number"、"bigint"或枚举类型。ts(2362(

将类型"string"转换为类型"Input"可能是一个错误,因为两种类型都没有充分重叠。如果这是有意的,请先将表达式转换为"未知"。ts(2352(

export const getTypeFormElem = ({
type = 'input',
typeValue = 'text',
...props
}) => {
if (type === 'textarea') return <TextArea value='123' { ...props } />;
if (type === 'checkbox') return <Checkbox { ...props } />;
if (type === 'date') return <DatePicker { ...props } />;
return <Input type={ typeValue } {...props } />;
};

进口组件

功能

你能解释一下如何解决这个问题吗?我做错了什么?

您应该将文件命名为.tsx,而不是.ts,因为其中有JSX…

相关内容

最新更新